1

我正在尝试通过配置文件设置条件插件执行。这个想法是有一个压缩/不压缩 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 配置文件的操作示例,我很感兴趣。此外,有谁知道是否可以通过属性在同一运行中激活多个配置文件?文档并不清楚。

4

1 回答 1

2

打开issue后发现这不是 bug,因为 section 中的属性只能是系统属性,不能是pom.xml本身定义的属性。

于 2012-01-30T10:19:17.580 回答