VictorGram
VictorGram

Reputation: 2661

Maven: How to use a plug in conditionally?

I have different profiles ( dev/local/qa/prod etc) defined in my pom.xml and I would like to activate a plug-in for any profile other than the profile called "local". Or in other word , I would like to de-activate that plug-in for the profile named as "local" this plug-in will change the permission of .sh type of files in a specific directory.

My plug-is :

<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>

Is there a way to do it?

Upvotes: 1

Views: 2433

Answers (2)

VictorGram
VictorGram

Reputation: 2661

This solution works too: ( notice "none" part under "phase" attribute here with the same execution id as defined for the plug-in)

<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>

Upvotes: 1

Alf
Alf

Reputation: 2321

Configure the plugin outside of the <profiles> section and use exec.skip property in local profile:

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

Upvotes: 2

Related Questions