I\'m using the maven release plugin on hudson with autoVersionSubmodules set to true to automatically increment the development version in the poms.
I\'m wondering i
The maven release plugin prompts you for the values of the release version to tag and also for the next development version. You can define these to avoid prompting; usually you would set them at the command line with something like mvn -DreleaseVersion=1.1.0 -DdevelopmentVersion=1.2.0-SNAPSHOT
.
However, if you are not getting prompted to select the version, then something is choosing for you. If you are using the M2 Release Plugin for Hudson then I think it has options to select the version for you, but you should probably find a way to configure them explicitly. More details about your particular setup would help.
...if there is a way to make the plugin increment the major version rather than minor version.
Currently when I'm at version 1.1.0-snapshot the next version is set to 1.1.1-snapshot but ideally I would like it to change to 1.2.0-snapshot.
What you are describing here is that maven-release-plugin is incrementing your fix version and you want the minor version incremented. Where version x.y.z
means [majorVersion].[minorVersion].[fixVersion]
.
The way I solved this is in the following manner:
pom.xml
increment it in the manner you are explaining and set the developmentVersion
and releaseVersion
as Hudson string parameters. developmentVersion
and releaseVersion
properties.Step 1:
import hudson.model.*
createReleaseAndDevelopmentVersions ();
def createReleaseAndDevelopmentVersions () {
def POM_LOCATION = build.parent.builds[0].properties.get("envVars")['WORKSPACE'] + "/pom.xml";
def SNAPSHOT_PART = "-SNAPSHOT";
def projectVersion = findOutCurrentVersion(POM_LOCATION);
def versionParts = projectVersion.tokenize('.');
def mayorVersionPart = versionParts[0];
def minorVersionPart = versionParts[1];
def fixVersionPart = versionParts[2];
def snapshotPartIndex = fixVersionPart.indexOf(SNAPSHOT_PART);
boolean hasSnapshotPart = snapshotPartIndex != -1;
if (hasSnapshotPart) {
fixVersionPart = fixVersionPart.substring(0, snapshotPartIndex);
}
int minorVersion = minorVersionPart.toInteger();
int fixVersion = fixVersionPart.toInteger();
def newFixVersion = 0;
def newMinorRelVersion;
def newMinorDevVersion;
if (hasSnapshotPart) {
newMinorRelVersion = minorVersion;
newMinorDevVersion = minorVersion + 1;
} else {
//TODO: either throw an exception here or change the newMinorRelVersion newMinorDevVersion appropriately to suite your use-cases:
//throw new IllegalArgumentException("The pom at location " + POM_LOCATION + " contains the version " + projectVersion + " which is not a snapshot version (missing " + SNAPSHOT_PART + "). This is a released version and nothing should happen to it!");
}
def releaseVersion = mayorVersionPart + "." + newMinorRelVersion + "." + newFixVersion;
def developmentVersion = mayorVersionPart + "." + newMinorDevVersion + "." + newFixVersion + SNAPSHOT_PART;
createJenkinsVariablesAndAddToCurrentJob(releaseVersion, developmentVersion);
}
def findOutCurrentVersion (POM_LOCATION) {
def thr = Thread.currentThread()
def build = thr?.executable
def projectVersionParam = "projectVersion"
def resolver = build.buildVariableResolver
def projectVersionParamValue = resolver.resolve(projectVersionParam)
return projectVersionParamValue
}
def createJenkinsVariablesAndAddToCurrentJob (releaseVersion, developmentVersion) {
def pa = new ParametersAction([
new StringParameterValue("releaseVersion", releaseVersion), new StringParameterValue("developmentVersion", developmentVersion)
])
Thread.currentThread().executable.addAction(pa)
}
Step 5 (the maven command):
clean release:clean release:prepare release:perform -DreleaseVersion=${releaseVersion} -DdevelopmentVersion=${developmentVersion}
Cheers,
Despot