我正在使用hudson上的maven release插件,并将autoVersionSubmodules设置为true,以自动增加poms中的开发版本。
我想知道是否有办法让插件增加主要版本而不是次要版本。
目前,当我处于1.1.0版快照时,下一个版本设置为1.1.1-snapshot,但理想情况下我希望将其更改为1.2.0-snapshot。
关于如何实现这一目标的任何想法?
感谢。
答案 0 :(得分:5)
maven release plugin会提示您输入要标记的发布版本的值以及下一个开发版本的值。您可以定义这些以避免提示;通常你会在命令行中设置它们mvn -DreleaseVersion=1.1.0 -DdevelopmentVersion=1.2.0-SNAPSHOT
。
但是,如果没有提示您选择版本,那么有些东西正在为您选择。如果您正在使用Hudson的M2 Release Plugin,那么我认为它有为您选择版本的选项,但您应该找到一种明确配置它们的方法。有关您的特定设置的更多详细信息将有所帮助。
答案 1 :(得分:4)
...如果有办法让插件增加主要版本 而不是次要版本。
目前,当我在版本1.1.0-snapshot时,设置了下一个版本 到1.1.1快照但理想情况下我希望它改为 1.2.0快照。
你在这里描述的是maven-release-plugin正在增加你的修复版本,你希望次要版本增加。版本x.y.z
表示[majorVersion].[minorVersion].[fixVersion]
。
我解决这个问题的方式如下:
pom.xml
中选择增量版本,并将developmentVersion
和releaseVersion
设置为Hudson字符串参数。 developmentVersion
和releaseVersion
属性调用maven release命令。第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)
}
步骤5(maven命令):
clean release:clean release:prepare release:perform -DreleaseVersion=${releaseVersion} -DdevelopmentVersion=${developmentVersion}
干杯,
暴君