Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Maven for non-Java projects (overriding clean/compile/install goals)

Tags:

java

maven

ant

I have a good(ish) understanding of using Maven for Java/WebApp projects but only to the point of following the default goals/lifecycle.

However I now have a Backup project which is not a Java project at all. I was thinking of configuring it with Maven to keep some consistency but am not sure how I override the main Maven goals/phases for my bespoke processing.

The Backup project needs to do the following: 'build' - initially, the backup outputs will be a mysql database dump file and a zip exported from an existing WebApp. But I want it to be flexible so calling an ant file to do the actual work (creating the dump, calling the WebApp, or doing whatever in the future) seems sensible. The output files could then be copied into the target directory.

'install' - publish the output files to a local repository, preferably providing a datetimestamp version number instead of the usual 1.0.0-SNAPSHOT version. I'd like to think that Maven can cope with an artefact being a collection of files, rather than a single jar/war, but not sure on this.

My pom.xml declares the packaging as 'pom' as 'jar' and 'war' dont seem appropriate here.

I then want other projects to be able to have a dependency on this Backup project so they can get the lastest backup artefacts if required.

1) how do I override the maven 'compile' goal to call an ant build file?

2) how do I override the maven 'install' goal to publish all files in the target directory but as a single artefact?

Any help/guidance appreciated.

like image 935
shuttsy Avatar asked Oct 21 '25 02:10

shuttsy


1 Answers

you can use maven antrun plugin for achieving this.

one example usage:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
                <id>bundle-virgo</id>
                <phase>package</phase>
                <configuration>
                <tasks>
                    <ant antfile="<path to build.xml>" target="compile"/>
                </tasks>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
           </execution>
        </executions>
    </plugin>
</plugins>

you can change the phase parameter to different maven phases to run it at different phases like package, compile etc.

like image 105
Ankit Kumar Avatar answered Oct 23 '25 15:10

Ankit Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!