2011-03-13 42 views
2

如何從maven-antrun-plugin獲取信息回Maven腳本?例如:如何從antrun中取回信息回maven?

[...] 
<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.6</version> 
    <executions> 
    <execution> 
     <phase>test</phase> 
     <goals> 
     <goal>run</goal> 
     </goals> 
     <configuration> 
     <target> 
      <exec ... resultproperty="foo"> 
     </target> 
     </configuration> 
    </execution> 
    </executions> 
</build> 
[...] 

我有興趣以後在Maven中使用此foo屬性。如何擺脫antrun

回答

1

我不知道,如果這個解決方案會工作,但也許你可以試試看:使用project.setProperty("foo.mvn", ${foo});

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.6</version> 
    <executions> 
    <execution> 
     <phase>test</phase> 
     <goals> 
     <goal>run</goal> 
     </goals> 
     <configuration> 
     <target> 
      <exec ... resultproperty="foo"> 

      <taskdef name="script" 
      classname="org.apache.tools.ant.taskdefs.optional.Script" 
      classpathref="maven.plugin.classpath" /> 
      <script language="javascript"> 
      <![CDATA[ 
      project.setProperty("foo.mvn", ${foo}); 
      ]]> 
      </script> 

     </target> 
     </configuration> 
    </execution> 
    </executions> 
    <dependencies> 
    <!-- Needed to run script (of Javascript) task. --> 
<dependency> 
    <groupId>ant</groupId> 
    <artifactId>ant-optional</artifactId> 
    <version>1.5.1</version> 
</dependency> 
<dependency> 
    <groupId>bsf</groupId> 
    <artifactId>bsf</artifactId> 
    <version>2.2</version> 
</dependency> 
<dependency> 
    <groupId>rhino</groupId> 
    <artifactId>js</artifactId> 
    <version>1.6R5</version> 
</dependency> 
<dependency> 
    <groupId>ant-contrib</groupId> 
    <artifactId>ant-contrib</artifactId> 
    <version>1.0b3</version> 
    <scope>runtime</scope> 
</dependency> 
    </dependencies> 
</plugin> 

的想法是使用定義的Maven可用的屬性(這裏稱爲foo.mvn) 。我在這裏使用JavaScript,所以你需要在antrun插件中添加一些依賴以便能夠運行它...

+0

哇...我會嘗試,但它看起來像一個矯枉過正的.. – yegor256 2011-03-15 11:26:29