【发布时间】:2012-02-21 13:23:48
【问题描述】:
我正在尝试通过配置文件设置条件插件执行。这个想法是压缩/不压缩 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 配置文件的操作示例,我很感兴趣。此外,有谁知道是否可以通过属性在同一运行中激活多个配置文件?文档不清楚。
【问题讨论】:
-
你试过用 -X 运行 maven 进行调试吗?您能否也描述一下您是如何从命令行运行 maven 的?
-
避免在您的个人资料 ID 中使用空格。尝试使用
mvn -P WithoutCompression或mvn -P DoCompress执行Maven。 -
@nico_ekito 我确实尝试删除 ids 中的空格,但问题仍然存在......
-
@Jeroen 我从 NetBeans 运行它。我试过 -X 但它没有产生有价值的信息。如果我指定配置文件,它们会运行,但不考虑激活部分信息...
标签: maven profile conditional-execution