diff --git a/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/invoker.properties b/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/invoker.properties
new file mode 100644
index 0000000000..0c2248c2a9
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/invoker.properties
@@ -0,0 +1,2 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-releases
+invoker.mavenOpts = -DprocessParent=true
diff --git a/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/pom.xml b/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/pom.xml
new file mode 100644
index 0000000000..d201a94d7c
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/pom.xml
@@ -0,0 +1,17 @@
+
+ 4.0.0
+
+
+ localhost
+ dummy-parent2
+ 3.0-SNAPSHOT
+
+
+ it-use-releases-issue-978-parent-snapshot
+ 1
+ pom
+
+ Test that parent is updated if it uses a snapshot version
+
+
diff --git a/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/verify.groovy b/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/verify.groovy
new file mode 100644
index 0000000000..cd6ea130c8
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-use-releases-issue-978-parent-snapshot/verify.groovy
@@ -0,0 +1,5 @@
+import groovy.xml.XmlSlurper
+
+def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
+
+assert project.parent.version == '3.0'
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java
index 8804f9c4d9..7f0b90cdbb 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java
@@ -509,28 +509,49 @@ protected boolean updateDependencyVersion(
boolean updated = false;
if (isProcessingParent()
&& getProject().getParent() != null
- && DependencyComparator.INSTANCE.compare(
- dep,
- DependencyBuilder.newBuilder()
- .withGroupId(
- getProject().getParentArtifact().getGroupId())
- .withArtifactId(
- getProject().getParentArtifact().getArtifactId())
- .withVersion(
- getProject().getParentArtifact().getVersion())
- .build())
- == 0
- && PomHelper.setProjectParentVersion(pom, newVersion)) {
- if (getLog().isDebugEnabled()) {
- getLog().debug("Made parent update from " + dep.getVersion() + " to " + newVersion);
+ && (DependencyComparator.INSTANCE.compare(
+ dep,
+ DependencyBuilder.newBuilder()
+ .withGroupId(getProject()
+ .getParentArtifact()
+ .getGroupId())
+ .withArtifactId(getProject()
+ .getParentArtifact()
+ .getArtifactId())
+ .withVersion(getProject()
+ .getParentArtifact()
+ .getVersion())
+ .build())
+ == 0
+ || getProject().getParentArtifact().getBaseVersion() != null
+ && DependencyComparator.INSTANCE.compare(
+ dep,
+ DependencyBuilder.newBuilder()
+ .withGroupId(getProject()
+ .getParentArtifact()
+ .getGroupId())
+ .withArtifactId(getProject()
+ .getParentArtifact()
+ .getArtifactId())
+ .withVersion(getProject()
+ .getParentArtifact()
+ .getBaseVersion())
+ .build())
+ == 0)) {
+ if (PomHelper.setProjectParentVersion(pom, newVersion)) {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Made parent update from " + dep.getVersion() + " to " + newVersion);
+ }
+ getChangeRecorder()
+ .recordChange(DefaultDependencyChangeRecord.builder()
+ .withKind(changeKind)
+ .withDependency(dep)
+ .withNewVersion(newVersion)
+ .build());
+ updated = true;
+ } else {
+ getLog().warn("Could not update parent: " + dep.toString() + " to " + newVersion);
}
- getChangeRecorder()
- .recordChange(DefaultDependencyChangeRecord.builder()
- .withKind(changeKind)
- .withDependency(dep)
- .withNewVersion(newVersion)
- .build());
- updated = true;
}
if (PomHelper.setDependencyVersion(
diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java
index 8580a04afd..e05be7f248 100644
--- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java
+++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java
@@ -105,6 +105,49 @@ public void testProcessParent()
"1.0.0-SNAPSHOT", "1.0.0")));
}
+ @Test
+ public void testProcessTimestampedParent()
+ throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException,
+ VersionRetrievalException {
+ setVariableValueToObject(mojo, "processParent", true);
+ mojo.getProject().setParent(new MavenProject(new Model() {
+ {
+ setGroupId("default-group");
+ setArtifactId("artifactA");
+ setVersion("1.0.0-SNAPSHOT");
+ }
+ }));
+ mojo.getProject()
+ .setParentArtifact(
+ new DefaultArtifact(
+ "default-group",
+ "artifactA",
+ "1.0.0-20230912.080442-1",
+ SCOPE_COMPILE,
+ "pom",
+ "default",
+ null) {
+ {
+ setBaseVersion("1.0.0-SNAPSHOT");
+ }
+ });
+
+ try (MockedStatic pomHelper = mockStatic(PomHelper.class)) {
+ pomHelper
+ .when(() -> PomHelper.setProjectParentVersion(any(), anyString()))
+ .thenReturn(true);
+ pomHelper
+ .when(() -> PomHelper.getRawModel(any(MavenProject.class)))
+ .thenReturn(mojo.getProject().getModel());
+ mojo.update(null);
+ }
+ assertThat(
+ changeRecorder.getChanges(),
+ hasItem(new DefaultDependencyVersionChange(
+ "default-group", "artifactA",
+ "1.0.0-SNAPSHOT", "1.0.0")));
+ }
+
@Test
public void testReplaceSnapshotWithRelease()
throws MojoExecutionException, XMLStreamException, MojoFailureException, VersionRetrievalException {