Maven配置文件未激活,但属性值正确

时间:2012-01-29 09:31:51

标签: maven profile conditional-execution

我正在尝试通过配置文件设置条件插件执行。我们的想法是压缩/不压缩HTML文件:

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

我分配给DoCompress属性的值无关紧要,不执行相应的配置文件。我用echo检查属性的值。为什么?我做错了什么?

是否允许使用属性值激活pom.xml中的多个配置文件?

更新

我创建了一个事件:我创建了一个事件:https://jira.codehaus.org/browse/MNG-5235

如果有人通过属性激活maven配置文件的操作示例,我感兴趣。此外,是否有人知道是否可以通过属性在同一次运行中激活多个配置文件?文档不清楚。

1 个答案:

答案 0 :(得分:2)

打开issue后,结果证明这不是错误,因为该部分中的属性只能是系统属性,而不是pom.xml本身定义的属性。