【问题标题】:Problem with picking up a -Dattribute in Maven using Antrun使用 Antrun 在 Maven 中获取 -Dattribute 的问题
【发布时间】:2011-04-12 11:08:05
【问题描述】:
所以我的 pom 中有这个 sn-p
<configuration>
<target if="csc" >
<echo>Unzipping md csc help</echo>
</target>
<target unless="csc">
<echo>Unzipping md help</echo>
</target>
</configuration>
当我正常使用 mvn 运行时,它会正确执行 unless="csc" 目标。问题是当我使用 -Dcsc=true 运行它时,它不会运行任何目标。
我做错了什么? :)
谢谢
【问题讨论】:
标签:
maven-2
maven-antrun-plugin
【解决方案1】:
antrun 插件似乎只支持配置中的单个目标元素。您可以使用maven profiles 达到与property is set or absent 激活时相同的效果:
<profiles>
<profile>
<id>property-set</id>
<activation>
<property>
<name>csc</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>antrun-property-set</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<target>
<echo>property is set</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>property-not-set</id>
<activation>
<property>
<name>!csc</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>antrun-property-not-set</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<target>
<echo>property is not set</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>