How to retrieve information from antrun back to maven?

拜拜、爱过 提交于 2020-01-04 11:46:20

问题


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:


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



来源:https://stackoverflow.com/questions/5289425/how-to-retrieve-information-from-antrun-back-to-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!