2010-06-17 39 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文件。