Maven calling Ant

Asked

Viewed 267 times

1

I have a Maven project, I want Maven to "call" some target of ant, I’ve seen that there is a plugin "Maven-antrun-plugin" there on the apache site, but I can’t understand any example, someone could give me a simple example, like creating a . jar(I know you can do this in Maven)just to know more or less how it works.

  • Using the maven-antrun-plugin it is possible to reference a build.xml of ant and thus their targets, have tried this?

  • That’s what I wanted to do, but I couldn’t find a good example that I could understand, you know, some article or something, that could point me?

1 answer

0


Using the maven-antrun-plugin you can use a file ant external.

As an example, let’s consider this build.xml containing a target for

<?xml version="1.0"?>
<project name="stack-test">
    <target name="showJavaVersion">
        <exec executable="java">
            <arg value="-version" />
        </exec>
    </target>
</project>

And refer to it in the build of our pom.xml as follows:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
                <target>
                    <ant antfile="${basedir}/build.xml">
                        <target name="showJavaVersion" />
                    </ant>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

While executing the life Cycle Compile(mvn compile) we’ll have a similar exit:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-antrum-example 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-antrum-example ---
[INFO] skip non existing resourceDirectory /usr/tmp/maven-antrum-example/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-antrum-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-antrun-plugin:1.8:run (compile) @ maven-antrum-example ---
[INFO] Executing tasks

main:

showJavaVersion:
     [exec] java version "1.8.0_60"
     [exec] Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
     [exec] Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.228 s
[INFO] Finished at: 2015-10-19T16:49:59-02:00
[INFO] Final Memory: 11M/368M
[INFO] ------------------------------------------------------------------------

Using directly on pom.xml, regardless of the build.xml, the equivalent configuration would be this:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
                <target name="showJavaVersion">
                    <exec executable="java">
                        <arg value="-version" />
                    </exec>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  • Man that’s what I wanted, old man thanks!!

  • Dude I did the example that you passed, worth mentioning that I use an internal repository of the company and that these artifacts have in the repositorio only in higher versions, and came out this following error in the console:

  • '[ERROR] Failed to execute Goal org.apache.Maven.plugins:Maven-antrun-plugin:1.3:run (Compile) on project Projectste: Execution Compile of Goal org.apache.Maven.plugins:Maven-antrun-plugin:1.3:run fa e resolved: The following artifacts could not be resolved: org.apache.Maven:Maven-plugin-api:jar:2.0.4, org.apache.Maven:Maven-project:jar:2.0.4, org.apache.Maven:Maven-Artifact:jar:2.0.4: Failure to was cached in the local Repository, Resolution will not be reattempted until the update interval of central has Elapsed or updates are Forced -> [Help 1]'

  • @emanuelcavalcante looks at the error Failure to was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced: This is because you failed for some reason, such as accessing repositories and getting the local cache. Either you force it to be downloaded, or you delete the cache. It’s something else, if you need to ask another question with more information

  • Then to be able to solve the problem, the version that antrun was requiring did not have in my local repositorio, so it could not be executed, but already working out, vlw man

  • @emanuelcavalcante ok, if it has been helpful consider accepting the answer as correct

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.