View on GitHub

PME @ Red Hat

Standardize Your Builds

Groovy Script Injection


PME offers the ability to run arbitrary groovy scripts on the sources prior to running the build. This allows PME to be extensible by the user and to process other files not just Maven POMs.

Warning : Do NOT alter POM files directly on the disk; they will get overwriten by the POM Manipulator. The Manipulator processes the POM files in memory and then writes them back out to disk. If you wish to alter the POM files access the Project class and call getModel() to retrieve the org.apache.maven.model.Model instance.


If the property -DgroovyScripts=<value>,.... is set, PME will load the remote Groovy script file.

The argument should a comma separated list of either:

If using a GAVTC, the remote groovy file can be deployed by e.g.


The deployed file can then be used with e.g.

mvn -DgroovyScripts=org.commonjava.maven.ext:depMgmt1:groovy:1.0 clean install

Groovy Scripts

The groovy script will be run once on the execution root (i.e. where Maven is invoked). By default groovy script will run after all the other Manipulators have run.

It is possible to configure it to run before all other manipulators by setting groovyManipulatorPrecedence to FIRST instead of the default LAST value.

Each script should use the BaseScript annotation:

@BaseScript org.commonjava.maven.ext.core.groovy.BaseScript pme
NOTE : As of PME 2.14 the API has changed: org.commonjava.maven.ext.core.groovy.BaseScript instead of org.commonjava.maven.ext.manip.groovy.BaseScript and org.commonjava.maven.ext.common.model.Project instead of org.commonjava.maven.ext.manip.model.Project

This make the following API available:

Method Description
Properties getUserProperties() Get the user properties.
File getBaseDir() Get the working directory (the execution root).
ProjectVersionRef) getGAV() Obtain the GAV of the current project
Project getProject() Return the current Project
ArrayList<ProjectVersionRef> getProjects() Returns the entire collection of Projects

This can then be invoked by e.g.


A typical groovy script that alters a JSON file on disk might be:

import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.transform.BaseScript
import groovy.util.logging.Slf4j

@BaseScript org.commonjava.maven.ext.core.groovy.BaseScript pme

public class Processor
    File basedir

    private void processJson(Map n) {

    def execute() {"Running ShrinkwrapProcessor...")

        def shrinkwrap = new File (basedir.toString() + File.separator +
            "shrink.json")"shrinkwrap json is " + shrinkwrap)

        if (shrinkwrap.exists()) {
   ("Found file {}", shrinkwrap)

            LinkedHashMap json = new



def Processor sp = new Processor(basedir:pme.getBaseDir()))

If a developer wishes to setup an IDE to write the groovy script we would recommend adding to the POM file and activating this profile within the IDE:

<!-- This profile is only used within IntelliJ for Groovy development -->