1

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.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • Have you tried running maven with -X for debug? Could you perhaps also describe how you run maven from the command line? – Jeroen Jan 29 '12 at 11:40
  • Avoid using spaces in the ids of your profile. Try to execute Maven with `mvn -P WithoutCompression` or `mvn -P DoCompress`. – ndeverge Jan 29 '12 at 13:40
  • Duplicate of [Maven Multiproject Profile activation via property](http://stackoverflow.com/a/8985198/267197), [How to activate profile by means of maven property](http://stackoverflow.com/a/5676534/267197) and [MNG-5055](http://jira.codehaus.org/browse/MNG-5055) (please vote for this bug). – dma_k Jan 29 '12 at 18:24
  • @nico_ekito I did try removing spaces in ids, but the issue remains... – Jérôme Verstrynge Jan 29 '12 at 23:59
  • @Jeroen I run it from NetBeans. I tried -X but it does not yield valuable information. If I specify profiles, they are run, but the activation section info is not taken into account... – Jérôme Verstrynge Jan 30 '12 at 00:04
  • Here is a workaround: http://stackoverflow.com/a/14386303/290918 – kldavis4 Jan 17 '13 at 21:42

1 Answers1

2

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.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453