Note regarding the accepted answer: I accepted the answer because of strong circumstantial evidence. Nonetheless, this is circumstantial evidence, so take it with a grain of salt.
How can I have a plugin be triggered when the user runs a plugin goal, not a lifecycle phase? (This has been asked before, but the answer was to use a lifecycle phase.)
Case in point: I need release:branch
to invoke regex-plugin
to generate a branch with the current version as its name, minus the -SNAPSHOT suffix. This is what I have, which requires the developer to activate a profile and invoke the verify
phase. I need the developer to simply invoke release:branch
, which in turn should cause regex-plugin
to run. In a bit of a marriage to Gitflow.
<profile>
<id>Release Branch</id>
<build>
<plugins>
<!-- On validate, compute the current version without -SNAPSHOT. -->
<!-- Put the result in a property. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<value>${project.version}</value>
<regex>^(.*)-SNAPSHOT$</regex>
<replacement>$1</replacement>
<name>project.unqualifiedVersion</name>
</configuration>
</execution>
</executions>
</plugin>
<!-- Also on validate, run the branch plugin, and use -->
<!-- the non-SNAPSHOT version thus computed in the branch name. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>branch</goal>
</goals>
<configuration>
<branchName>release/${project.unqualifiedVersion}</branchName>
<updateWorkingCopyVersions>true</updateWorkingCopyVersions>
<updateBranchVersions>false</updateBranchVersions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
The intent is for release:branch
to move the current snapshot version (say, 1.0.5-SNAPSHOT
) into a new branch, which should be named after the version but without the superfluous -SNAPSHOT
suffix (1.0.5
). The current branch should then take on a new snapshot version (1.1.0-SNAPSHOT
, not 1.0.6-SNAPSHOT
, because we want release 1.0.x
to have room for hotfixes, so we reserve it for the branch) (I don't have the automatic computation of the next snapshot version figured out yet, so, if you run the Maven configuration above with validate
, you will have to enter it at a prompt).
prepare
goal supportspreparationGoals
, that sounds like what you'd want for thebranch
goal. – PeasecodpreparationGoals
, as it lacks structure in an otherwise highly structured file format. – Unwishbranch
goal (rather to theprepare
goal). – PeasecodpreparationGoals
were available tobranch
, it would be enough to solve my problem, albeit a shortsighted solution.completionGoals
should also be included with it, to allow post-processing. In any case, it seems like Maven is meant to expose only highly controlled entry points (barring writing your custom Mojos), so it may not be the most adapted tool for managing Gitflow activities. – UnwishSNAPSHOT
stripped to begin with, assuming it's a branch for a release that was done withprepare
. – Peasecoddevelop
, which is always on a-SNAPSHOT
version. – Unwishregex-plugin
andrelease:branch
withexec:exec
, no profiles or binding to custom phases required. – Wulferelease:branch
overexec:exec
. Moreover, there will be other operations that will need to be overloaded in order to marry Maven's branching model with Gitflow, and I only have oneexec:exec
to use. – Unwishproperties-maven-plugin
to load properties from a file to be available to the release plugin. What did you end up deciding/doing in the end? – Utgardlokiproperties-maven-plugin
during the context of my release:prepare/perform goals, but given that the release plugin is called directly (specifying the plugin:goal), there is no way to call the other plugin in the same context, short of specifying the specific goal in the properties plugin within the same mvn cmd. Basically, looking for a custom lifecycle in which I can map the different plugins and goals myself but without having to create a custom lifecycle.... – Utgardloki