Question

I am trying to set-up conditional plugin execution via profiles. The idea is to have a compress/no compress HTML files:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net</groupId>
    <artifactId>mavenconditionalexecution</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>Maven Conditional Execution</name>

    <properties>
        <DoCompress>true</DoCompress>
    </properties>

    <build>
        <plugins>

            <!-- Clean-up -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>clean</phase>
                        <configuration>
                            <target>
                                <echo message="DoCompress: ${DoCompress}"/>
                                <delete includeemptydirs="true">
                                    <fileset dir="${basedir}/src/main/webapp/result/" includes="**/*"/>
                                </delete>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <resources>
          <resource>
            <directory>${basedir}/src/main/webapp/html</directory>
          </resource>
        </resources>

    </build>

    <profiles>

        <profile>
            <id>With Compression</id>
            <activation>
                <property>
                    <name>DoCompress</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.tunyk.mvn.plugins.htmlcompressor</groupId>
                        <artifactId>htmlcompressor-maven-plugin</artifactId>
                        <version>1.2</version>
                        <executions>
                            <execution>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>html</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <goalPrefix>htmlcompressor</goalPrefix>
                            <srcFolder>${basedir}/src/main/webapp/html</srcFolder>
                            <targetFolder>${basedir}/src/main/webapp/result/html</targetFolder>
                            <removeIntertagSpaces>true</removeIntertagSpaces>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>Without Compression</id>
            <activation>
                <property>
                    <name>DoCompress</name>
                    <value>false</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <phase>process-resources</phase>
                                <configuration>
                                    <target>
                                        <echo message="Copying file"/>
                                        <copy todir="${basedir}/src/main/webapp/result/">
                                            <fileset dir="${basedir}/src/main/webapp/html/" >
                                                <include name="angle.html"/>
                                            </fileset>
                                        </copy>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>

        </profile>

    </profiles>

    <dependencies>
        <dependency>
            <groupId>com.tunyk.mvn.plugins.htmlcompressor</groupId>
            <artifactId>htmlcompressor-maven-plugin</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>

</project>

It does not matter what value I assign to the DoCompress property, the corresponding profile are not executed. I check the value of the property with an echo. Why? What am I doing wrong?

Is it allowed to activate multiple profiles in a pom.xml using property values?

UPDATE

I have created an incident: I have created an incident: https://jira.codehaus.org/browse/MNG-5235.

If anyone has an operational example of maven profile activation by properties, I am interested. Moreover, does anyone know whether multiple profiles can be activated in the same run via properties? The documentation is not clear about it.

Was it helpful?

Solution

After opening an issue, it turns out this is not a bug, because properties in the section can only be system properties, not properties defined in the pom.xml itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top