Maven:如何有条件地使用插件?

时间:2019-01-15 19:48:02

标签: maven maven-plugin

我在pom.xml中定义了不同的配置文件(dev / local / qa / prod等),我想为除名为“ local”的配置文件以外的任何配置文件激活一个插件。换句话说,我想为名为“ local”的配置文件停用该插件,该插件将更改特定目录中.sh类型文件的权限。

我的插件是:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
        <execution>
            <id>script-chmod</id>
            <phase>install</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>sh</executable>
                <arguments>
                    <argument>-c</argument>
                    <argument>chmod 744 ${SCRIPT_INSTALL_DIR}/*.sh</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

有办法吗?

2 个答案:

答案 0 :(得分:1)

<profiles>部分之外配置插件,并在本地配置文件中使用exec.skip属性:

<profile>
    <id>local</id>
    <properties>
        <exec.skip>true</exec.skip>
    </properties>
</profile>

答案 1 :(得分:0)

此解决方案也有效:(请注意,此处“ phase”属性下的“ none”部分具有与该插件所定义的执行ID相同的执行ID)

<profile>
        <id>local</id>
        <activation/>
        <properties>
            <INSTALL_MACHINE_LIST>....</INSTALL_MACHINE_LIST>
            <COPY_MODE>auto</COPY_MODE>
            <current_env>......</current_env>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.6.0</version>
                    <executions>
                        <execution>
                            <id>script-chmod</id>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>