我在我的pom.xml中使用了maven-antrun-plugin,并使用了外部的ant文件,在插件的文档中写道:"Maven的所有属性在目标配置中也是可用的。
Maven的所有属性在目标配置中也是可用的。但是,你可能希望使用ant任务来调用外部Ant构建脚本。为了避免名称冲突,只有一部分属性会传递给外部Ant构建。这些属性包括在POM的属性部分定义的所有属性。 它还包括一些常用的Maven属性的前缀版本。
所以这是我的pom,在这里我定义了 "test.prop "属性。
<?xml version="1.0" encoding="UTF-8"?>
<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>testant</groupId>
<artifactId>testant</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<test.prop>TestPropValue</test.prop>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>optional</artifactId>
<version>1.5.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-index-properties</id>
<phase>install</phase>
<configuration>
<tasks>
<!--<property name="test.prop" value="${test.prop}"/>-->
<ant antfile="build.xml">
<target name="echo-prop"/>
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
并试图在build. xml中呼应这个属性。
<project default="test">
<target name="echo-prop">
<echo>${test.prop}</echo>
</target>
</project>
我得到的结果是:
echo-prop:
[echo] ${test.prop}
所以,根据文档,属性没有得到应有的解决。而且只有在我取消 "tasks "标签下显式属性声明行的comment时,才会正常工作。
谢谢你的帮助
你应该为antrun-plugin指定一个版本。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version><!--$NO-MVN-MAN-VER$-->
(...)
</plugin>
ant默认会将父类的所有属性传递给底层的 "ant"-call。除非你定义 inheritAll=false,否则所有的属性都会被传递。
在这种情况下,你应该看看有效的pom。那里定义了一个非常古老的antrun-plugin版本。只要你换成最新的版本,例子代码就能用了。