How to retrieve information from antrun back to ma

2019-07-21 18:29发布

How can I get information from maven-antrun-plugin back to Maven script? For example:

[...]
<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>
[...]

I'm interested to use this foo property later in Maven. How to it get out of antrun?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-21 19:02

I am not sure if this solution will work, but maybe you can give it a try:

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

The idea is to use define a property available for Maven (called here foo.mvn) by using the project.setProperty("foo.mvn", ${foo});. I am using JavaScript here, so you need to add some dependencies in the antrun plugin to be able to run it...

查看更多
登录 后发表回答