2

如何从maven-antrun-plugin获取信息返回到 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>
[...]

我有兴趣foo稍后在 Maven 中使用此属性。如何摆脱它antrun

4

1 回答 1

1

我不确定此解决方案是否有效,但也许您可以尝试一下:

<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>

这个想法是foo.mvn通过使用project.setProperty("foo.mvn", ${foo});. 我这里使用的是 JavaScript,所以你需要在antrun插件中添加一些依赖项才能运行它...

于 2011-03-14T08:31:50.873 回答