Friday, 24 January 2014

There will always come a point in a Maven based project where you have to execute different parametrized Maven builds and their number increases and increases...

IDE support for Maven builds

Fortunately you favorite IDEs support saving of different Maven builds: Eclipse with its launchers, NetBeans with the customized Maven builds submenu.
But their storing of build informations is different: Eclipse creates *.launch files and NetBeans nb-actions*.xml files. If they are checked in colleagues will be "not amused" to see these config files, when they happen to use another IDE (I know that officially a project always uses the same IDE... but you know the truth!). So is there a unique way that serves all IDEs/developers well?
Yes, the good all well supported Ant world!

Execute Maven Builds from one Ant build.xml

Here is an Ant build.xml that executes the standard Maven goals:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Maven Launcher">
  <property name="maven.executable" value="mvn.bat" />
 
  <target name="mvn package">
    <exec executable="${maven.executable}">
      <arg value="package" />
    </exec>
  </target>

  <target name="mvn test">
    <exec executable="${maven.executable}">
      <arg value="test" />
    </exec>
  </target>

  <target name="mvn clean package">
    <exec executable="${maven.executable}">
      <arg value="clean" />
      <arg value="test" />
    </exec>
  </target>
</project>
This gives you a first impression of how to call the "mvn" executable and pass command line arguments to it. Following this it is easy to call even more parametrized (with system properties and profile) builds:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Maven Launcher">
  ...
  <property name="maven.executable" value="mvn.bat" />
 
  <target name="Performance Tests (Backend, offline)">
    <exec executable="${maven.executable}" failonerror="true">
      <arg value="clean" />
      <arg value="verify" />
      <arg value="-Pperformance" />
      <arg value="-Dscope=backend" />
      <arg value="-Dtest.env=DEV" />
      <arg value="-o" />
    </exec>
  </target>
  ...
</project>
That's it! Now you can put all your Maven calls into one place. Give them reasonable names and it is easy to navigate through the build.xml using your IDE's Ant view.

1 comment:


  1. Its very useful to me. Wonderful blog.. Thanks for sharing informative Post.

    Installment loans
    Payday loans
    Title loans

    ReplyDelete