Search code examples
javamavenmaven-antrun-plugin

Run specific standalone ant target from Maven


I've got the following plugin defined in my POM in an attempt to deploy the maven produced .war file either on our test or production tomcat server:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.7</version>
  <configuration>
    <target name="test-deploy">
      <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
        <deploy 
          path="/${project.name}" 
          url="http://test-server:8080/manager/text" 
          username="user" 
          password="pass"
          war="file:${project.build.directory}/${project.build.finalName}.${project.packaging}" 
          update="true"/>
    </target>
    <target name="prod-deploy">
      <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
        <deploy 
          path="/${project.name}" 
          url="http://prod-server:8080/manager/text" 
          username="user" 
          password="pass"
          war="file:${project.build.directory}/${project.build.finalName}.${project.packaging}" 
          update="true"/>
    </target>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-catalina-ant</artifactId>
      <version>8.0.14</version>
    </dependency>
  </dependencies>
</plugin>

From reading the Maven AntRun Plugin usage it looks like I should be able to add a target name (as I've done), but I'm not sure how to invoke a specific target. The web-deploy target is the only target run even if I try to invoke only the test-deploy target with:

mvn antrun:run -Dtarget=test-deploy

How do I specify which ant target I'd like to run?


Solution

  • AFAIK, this is not possible.

    I suggest using maven profiles to split the maven tasks and calling them with maven's ability to trigger profiles based on conditions or command line parameters.
    It means that each profile will declare its own maven-antrun-plugin, but will give you the flexibility to call them individually.

    I hope this helps.