Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: Let "mvn -Pjenkins" be the same as "mvn clean install pmd:pmd javadoc:aggregate"

We have a number of Maven jobs in our Jenkins instance, each with their own particular invocation string specified in the build configuration similar to

mvn clean install -DDISABLED="javadoc:aggregate" checkstyle:checkstyle pmd:pmd findbugs:findbugs

I would like to consolidate this so that the invocation string is stored somewhere in the POM along with suitable profile information so we can replace the invocation strings of all these slightly different jobs with a

mvn -Pjenkins

standard invocation. To my understanding the defaultGoal entry only supports a single goal which on first glance seems to be insufficient for representing our multiple goals, but might be enough if we can make it correspond to multiple entries instead. If at all possible I would like avoid setting up profile specific bindings to standard lifecycle phases if a simple invocation string will do.

like image 317
Thorbjørn Ravn Andersen Avatar asked Mar 13 '13 12:03

Thorbjørn Ravn Andersen


2 Answers

I don't think there's a direct way to give Maven an invocation string. As you say, you can add a custom 'jenkins' profile in which you configure the checkstyle, pmd, and findbugs plugins to be bound to a build phase (e.g. their default phase). You would still need to run mvn -Pjenkins clean install though. However this has the advantage that you can also add custom config to those plugins (e.g. to include test code in the PMD coverage).

like image 28
artbristol Avatar answered Nov 15 '22 05:11

artbristol


You can configure additional mojos ina profile, and you can bind mojos to life cycle phases. These two things combined will allow you to run additional mojos when a certain profile is given.

This is a standard techniqued used throughout in Maven. For example, when you run "mvn release:perform", it runs a nested Maven session with "-Prelease" that does additional things, such as GPG-signing binaries.

<profile>
  <id>jenkins</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>findbugs</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ... other mojos ...

The findbugs mojo is bound by default to the compile phase, so this gets invoked automatically at the compilation phase. If you want to use a mojo that doesn't bind to any lifecycle phase by default, you add <phase>...</phase>.

See our POM in the Jenkins core for a complete example where we invoke FindBugs. The other mojos are the basically the same.

Note that for this to work, your default goal needs to invoke the life cycle phase to the certain point (say package or install.)

like image 166
Kohsuke Kawaguchi Avatar answered Nov 15 '22 05:11

Kohsuke Kawaguchi