in maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java [538:624]
private void rewriteArtifactVersion(
MavenCoordinate artifact,
Model projectModel,
Properties properties,
ReleaseResult result,
ReleaseDescriptor releaseDescriptor,
boolean simulate)
throws ReleaseExecutionException, ReleaseFailureException {
String projectId = ArtifactUtils.versionlessKey(projectModel.getGroupId(), projectModel.getArtifactId());
String rawVersion = artifact.getVersion();
if (rawVersion == null) {
// managed dependency or unversioned plugin
return;
}
String rawGroupId = artifact.getGroupId();
if (rawGroupId == null) {
if ("plugin".equals(artifact.getName())) {
rawGroupId = "org.apache.maven.plugins";
} else {
// incomplete dependency
return;
}
}
String groupId = ReleaseUtil.interpolate(rawGroupId, projectModel);
String rawArtifactId = artifact.getArtifactId();
if (rawArtifactId == null) {
// incomplete element
return;
}
String artifactId = ReleaseUtil.interpolate(rawArtifactId, projectModel);
String key = ArtifactUtils.versionlessKey(groupId, artifactId);
String resolvedSnapshotVersion = getResolvedSnapshotVersion(key, releaseDescriptor);
String mappedVersion = getNextVersion(releaseDescriptor, key);
String originalVersion = getOriginalVersion(releaseDescriptor, key, simulate);
if (originalVersion == null) {
originalVersion = getOriginalResolvedSnapshotVersion(key, releaseDescriptor);
}
// MRELEASE-220
if (mappedVersion != null
&& mappedVersion.endsWith(Artifact.SNAPSHOT_VERSION)
&& !rawVersion.endsWith(Artifact.SNAPSHOT_VERSION)
&& !releaseDescriptor.isUpdateDependencies()) {
return;
}
if (mappedVersion != null) {
if (rawVersion.equals(originalVersion)) {
logInfo(result, " Updating " + key + " to " + mappedVersion);
artifact.setVersion(mappedVersion);
} else {
String property = extractPropertyFromExpression(rawVersion);
if (property != null) {
if (property.startsWith("project.") || property.startsWith("pom.") || "version".equals(property)) {
// those properties are read-only, replace with literal version in case it is supposed to be
// different from the project's version
if (!mappedVersion.equals(getNextVersion(releaseDescriptor, projectId))) {
logInfo(result, " Updating " + key + " to " + mappedVersion);
artifact.setVersion(mappedVersion);
} else {
logInfo(result, " Ignoring artifact version update for expression " + rawVersion);
}
} else {
rewritePropertyUsedInVersionExpression(
projectId,
key,
rawVersion,
mappedVersion,
originalVersion,
property,
properties,
result,
releaseDescriptor);
}
}
}
} else if (resolvedSnapshotVersion != null) {
logInfo(result, " Updating " + key + " to " + resolvedSnapshotVersion);
artifact.setVersion(resolvedSnapshotVersion);
} else {
// artifact not related to current release
}
}