Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass arguments from 'maven' to ant task

Tags:

maven

ant

I want to be able to pass configuration values from maven to ant. If that makes sense.

I want to be able to pass variables to this task:

Let's say I define a variable ${someArg} I want to be able to pass 'someArg' to the maven script and eventually to the build.xml ant script.

Here is my definition:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>gen</id>
            <phase>generate-resources</phase>
            <configuration>
                <target name="main">
                    <script language="javascript" manager="javax"
                    src="${project.basedir}/src/scripts/myfile.js"/>
                </target>
            </configuration>
            <goals>
  ${someArg}  (how to pass someArg)
                <goal>run</goal>
            </goals>
        </execution>
...

And then here is part of the build.xml:

<?xml version="1.0" ?> <project name="deployment" default="deploy">
     <property file="build.properties" />
  <target>
   <echo message="${someArg}" />
  </target>
</project>

And I want to pass to build.xml

like image 364
Berlin Brown Avatar asked Oct 05 '22 00:10

Berlin Brown


1 Answers

There is an example in: http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

In your configuration pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
      <execution>
        <id>compile</id>
        <phase>compile</phase>
        <configuration>
          <target>
            <property name="compile_classpath" refid="maven.compile.classpath"/>
            <property name="runtime_classpath" refid="maven.runtime.classpath"/>
            <property name="test_classpath" refid="maven.test.classpath"/>
            <property name="plugin_classpath" refid="maven.plugin.classpath"/>

            <echo message="compile classpath: ${compile_classpath}"/>
            <echo message="runtime classpath: ${runtime_classpath}"/>
            <echo message="test classpath:    ${test_classpath}"/>
            <echo message="plugin classpath:  ${plugin_classpath}"/>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Maven documentation says that you can put anything in the target tag, so you should be able to use maven properties in the target using the ${property name}.

like image 77
Zilvinas Avatar answered Oct 10 '22 03:10

Zilvinas