使用特定配置文件时禁用Maven插件 [英] Disable maven plugins when using a specific profile

查看:137
本文介绍了使用特定配置文件时禁用Maven插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要在特定配置文件中运行,我正在寻找一种禁用插件执行的方法.

I'm looking to find a way of disabling a plugin execution if running with a particular profile.

这与运行插件(如果选择了配置文件)相反.

.

我的用例:我的Maven构建有很多插件,但是在我的开发机上运行时,我想跳过其中的一些插件.我希望能够仅使用"dev"配置文件运行构建,而不是在本地将这些插件注释掉.这些插件将继续在我的持续构建中运行.

My use case: My Maven build has a whole load of plugins, but when running on my dev machine, I want to skip some of them. Instead of commenting those plugins out locally, I want to be able just run the build with a "dev" profile. The plugins would continue to run on my continuous build.

想法?

推荐答案

当特定配置文件处于活动状态时,有一种巧妙的方法可以禁止插件执行.

首先,您需要为插件执行添加一个标识符,例如:

Firstly you need to add an identifier to plugin execution like:

<build>
    <plugins>
        <!-- (...) -->
        <plugin>
            <groupId>nl.geodienstencentrum.maven</groupId>
            <artifactId>sass-maven-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>styles-compilation</id> <!-- plugin execution identifier -->
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>update-stylesheets</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

然后,您需要定义一个配置文件,在该配置文件中将不执行此插件:

Then you need to define a profile in which this plugin will NOT be executed:

<profiles>
    <profile>
        <id>no-sass</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>nl.geodienstencentrum.maven</groupId>
                    <artifactId>sass-maven-plugin</artifactId>
                    <version>2.1</version>
                    <executions>
                        <execution>
                            <id>styles-compilation</id> <!-- here there must be the same identifier as defined in <build><plugins> section -->
                            <phase>none</phase> <!-- this disables plugin -->
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

现在,如果您运行标准的Maven构建:

Now if you run standard maven build:

mvn clean package

sass-maven-plugin 将被执行,但在运行时:

the sass-maven-plugin will be executed, yet when running:

mvn clean package -P no-sass

不会执行sass-maven-plugin .

the sass-maven-plugin will not be executed.

这篇关于使用特定配置文件时禁用Maven插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆