How to install build.xml for Groovy Antbuilder?

I want to execute build.xml (Ant buildfile) using GMaven (Maven plugin for embedded Groovy execution in POM). Since I have to execute buildfile multiple times using maven-antrun-plugin this is not an option. The assembly file is developed and taken from the partner project with minor modifications. So I don't want to embed logic in it in another environment (groovy or Maven config).

I am taking a list of properties (environment and machine names which can vary greatly in number and names, in my opinion this cannot be put into modules) from an XML file and want to do ant builds for each of these machines.I found the executeTarget method in javadocs, but not how to set the location of the build file. How can I do this - is that enough?

What looks like this for me:

<plugin>
    <groupId>org.codehaus.groovy.maven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <executions>
      <execution>
        <id>some ant builds</id>
        <phase>process-sources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <source>
            def ant = new AntBuilder()
            def machines = new XmlParser().parse(new File(project.build.outputDirectory + '/MachineList.xml'));

            machines.children().each { 

             log.info('Creating machine description for ' + it.Id.text() + ' / ' + it.Environment.text());
                ant.project.setProperty('Environment',it.Environment.text());
                ant.project.setProperty('Machine',it.Id.text());

                // What missing?                    

                ant.project.executeTarget('Tailoring');

            }

            log.info('Ant has finished.')

          </source>
        </configuration>
      </execution>
    </executions>
  </plugin>

      

+2


a source to share


2 answers


The solution is using the Project and ProjectHelper classes from org.apache.tools.ant like this (excluding other details from my task):

import org.apache.tools.ant.Project
import org.apache.tools.ant.ProjectHelper

def antFile = new File('src/main/ant/myBuildfile.xml')

//create a project with the buildfile
def antProject = new Project()
antProject.init()
ProjectHelper.projectHelper.configureProject(antProject, antFile)

// run it with ant and set the target
antProject.executeTarget('myTarget');

      

There is no registration here. I used



antProject.addBuildListener(antListener)

      

to add a personalized listener as you found it here - that's where I got it dissolves after a while ...

+2


a source


You can use maven-antrun-plugin directly .



If you did it because of a loop, perhaps you can have one module per machine and use a section <pluginManagement>

in the parent pump to avoid duplicating the maven-antrun-plugin configuration.

0


a source







All Articles