2010-06-17 42 views
4

我已经嵌入我的POM中下面的代码:出口Maven的性质

<plugin name="test"> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
     <executions> 
     <execution> 
      <phase>validate</phase> 
      <configuration> 
       <tasks> 
       <pathconvert targetos="unix" property="project.build.directory.portable"> 
        <path location="${project.build.directory}"/> 
       </pathconvert> 
       </tasks> 
      </configuration> 
      <goals> 
     <goal>run</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 

我然后引用${project.build.directory.portable}run project行动,但它回来作为null。在Ant块中执行<echo>显示正确的值。我究竟做错了什么?

回答

11

为了完整性,mentioned feature在2010年10月的maven-antrun-plugin中实施。

您正在查找的配置参数是exportAntProperties。使用

例子:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.7-SNAPSHOT</version> 
    <executions> 
     <execution> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>run</goal> 
      </goals> 
      <configuration> 
       <target> 
        <exec outputproperty="svnversion" 
         executable="svnversion"> 
         <arg value=".." /> 
        </exec> 
       </target> 
       <exportAntProperties>true</exportAntProperties> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

作为一个侧面说明,在这个岗位(2011-10-20)的时候,官方插件文档没有这个选项记录。要获得帮助,该插件的“versionXYZ”:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-antrun-plugin:versionXYZ -Ddetail 
+0

嗯,它真的有用吗?根据这个问题我有一些麻烦(http://maven.40175.n5.nabble.com/exportAntProperties-not-working-in-3 -0-4-td5732071.html) – milgoff 2014-01-06 08:49:55

+1

尝试将exportAntProperties设置为全局配置,而不是执行配置 – Joram 2014-01-13 13:07:09

+1

我注意到这不会覆盖已经在POM中声明的属性,但是如果我不声明属性my linter(使用IntelliJ)抱怨未知的属性符号。有没有办法告诉它忽略这个,或者告诉插件重写一个现有的属性? – 2015-09-11 20:07:19

0

我不会认为您可以设置一个属性,从Ant可以从Maven中看到。你应该写一个Mojo。

+0

换言之:即使在Windows下,您如何确保$ {basedir}包含unix风格的斜杠? – Gili 2010-06-18 15:37:49

+0

@Gili我不在Windows下,所以我无法广泛测试(抱歉,懒得启动虚拟机),但我不认为你可以。我仍然不明白为什么你需要这个,但如果是这样的话,我会将'basedir'属性注入Mojo中,使用unix风格的斜杠重写它,并将它暴露在另一个属性中。 – 2010-06-18 15:52:11

+0

当然,但这需要我写一个新的魔咒。现有的插件没有一个优雅的方式吗? – Gili 2010-06-19 23:57:00

0

从插件文档here

尝试添加maven前缀,所以你必须 <path location="${maven.project.build.directory}"/>代替

如果不工作,你可能需要自己显式地重新定义属性:

<property name="maven.project.build.dir" value="${project.build.directory}"/> 
<path location="${maven.project.build.directory}"/> 
3

行家-antrun-插件的1.7版本为我工作,从蚂蚁传递一个属性到Maven(从MVN到蚂蚁)。计算一个文件,后来它存储为属性,该属性MVN在稍后时间访问的MD5校验和一些示例代码:

<artifactId>maven-antrun-plugin</artifactId> 
<version>1.7</version> 
<executions> 
    <execution> 
     <id>ant-md5</id> 
     <phase>initialize</phase> 
     <goals> 
     <goal>run</goal> 
     </goals> 
    <configuration> 

<target> 
    <property name="compile_classpath" refid="maven.compile.classpath"/> 
    <property name="outputDir" value="${project.build.outputDirectory}"/> 
    <property name="sourceDir" value="${project.build.sourceDirectory}"/> 
    <checksum file="${sourceDir}/com/blah/db/blah.java" property="blah.md5db"/> 
</target> 
<exportAntProperties>true</exportAntProperties> 
</configuration> 
</execution> 
</executions> 

该物业是在访问后与$ {} blah.md5db在java文件。