Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set a maven property from ant?

I tried to use the maven-antrun-plugin to check in a first execution if a file exists and then set a property accordingly. In another execution (another phase) of the antrun-plugin I want to make use of the property. But the property set in one execution cannot be used in another execution since it's an ant and not a maven property and doesn't get propagated.

Is it possible to propagate the ant property to maven or in other words set a maven property from ant?

Using another Maven build like in this question is not an option.

Another way that might work somehow would be an external build.xml but that's not an option too, because I have to keep things in one pom.

I've read about using GMaven to set a Maven property but I would like to stay with ant.

like image 474
Jan Avatar asked Feb 21 '11 09:02

Jan


People also ask

Can we use Maven and Ant together?

You can use the maven-antrun-plugin to invoke the ant build. Then use the build-helper-maven-plugin to attach the jar produced by ant to the project. The attached artifact will be installed/deployed alongside the pom. If you specify your project with packaging pom , Maven will not conflict with the ant build.

What is Maven AntRun plugin used for?

This plugin provides the ability to run Ant tasks from within Maven. You can even embed your Ant scripts in the POM! It is not the intention of this plugin to provide a means of polluting the POM, so it's encouraged to move all your Ant tasks to a build.

Which goal is used to invoke ant tasks for a maven build?

The maven-antrun-plugin has only one goal, run . This allows Maven to run Ant tasks.


2 Answers

As of version 1.7 of the maven-antrun-plugin it is possible according to the plugin documentation (see exportAntProperties). So, I guess, in earlier versions: it's not ;-).

like image 102
Jan Avatar answered Sep 18 '22 13:09

Jan


you can redirect your strategy to activation of different profiles depending on the existence of the file instead of antrun-plugin:

<profiles>
    <profile>
        <id>notExist</id>
        <activation>
          <file>
            <missing>target/maven-archiver/notExist.properties</missing>
          </file>
        </activation>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                  <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>not exist</echo>
                        </tasks>
                    </configuration>
                  </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

<profile>
    <id>exist</id>
    <activation>
      <file>
        <exists>target/maven-archiver/pom.properties</exists>
      </file>
    </activation>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                  <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>not exist</echo>
                        </tasks>
                    </configuration>
                  </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

You can use activation profiles maven features to distinguish between one configuration and another according the activation criteria.

I use the antrun-plugin in example only for do the echo

like image 38
Montells Avatar answered Sep 21 '22 13:09

Montells