diff --git a/src/it-repo/dummy-parent4-70.pom b/src/it-repo/dummy-parent4-70.pom
new file mode 100644
index 000000000..b0e715a74
--- /dev/null
+++ b/src/it-repo/dummy-parent4-70.pom
@@ -0,0 +1,9 @@
+
+ 4.0.0
+
+ localhost
+ dummy-parent4
+ 70
+ pom
+
diff --git a/src/it-repo/dummy-parent4-71-SNAPSHOT.pom b/src/it-repo/dummy-parent4-71-SNAPSHOT.pom
new file mode 100644
index 000000000..d4efa088d
--- /dev/null
+++ b/src/it-repo/dummy-parent4-71-SNAPSHOT.pom
@@ -0,0 +1,9 @@
+
+ 4.0.0
+
+ localhost
+ dummy-parent4
+ 71-SNAPSHOT
+ pom
+
diff --git a/src/it/it-update-parent-005-issue-670/invoker.properties b/src/it/it-update-parent-005-issue-670/invoker.properties
new file mode 100644
index 000000000..f95f04c75
--- /dev/null
+++ b/src/it/it-update-parent-005-issue-670/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-parent -DparentVersion=71-SNAPSHOT -DallowSnapshots
\ No newline at end of file
diff --git a/src/it/it-update-parent-005-issue-670/pom.xml b/src/it/it-update-parent-005-issue-670/pom.xml
new file mode 100644
index 000000000..a06e670cd
--- /dev/null
+++ b/src/it/it-update-parent-005-issue-670/pom.xml
@@ -0,0 +1,16 @@
+
+
+ 4.0.0
+
+
+ localhost
+ dummy-parent4
+ 70
+
+
+ localhsot
+ issue-670
+ 0.31-SNAPSHOT
+ pom
+
+
\ No newline at end of file
diff --git a/src/it/it-update-parent-005-issue-670/verify.groovy b/src/it/it-update-parent-005-issue-670/verify.groovy
new file mode 100644
index 000000000..9e458aecc
--- /dev/null
+++ b/src/it/it-update-parent-005-issue-670/verify.groovy
@@ -0,0 +1,3 @@
+pom = new File( basedir, "pom.xml" ).text
+
+assert pom =~ /71-SNAPSHOT<\/version>/
\ No newline at end of file
diff --git a/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java b/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
index 68893603f..46db1a384 100644
--- a/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
+++ b/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
@@ -134,15 +134,13 @@ protected void update( ModifiedPomXMLEventReader pom )
ArtifactVersion artifactVersion;
try
{
- artifactVersion = findLatestVersion( artifact, versionRange, false, true,
- allowDowngrade );
+ artifactVersion = findLatestVersion( artifact, versionRange, null, false, allowDowngrade );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
-
if ( !shouldApplyUpdate( artifact, currentVersion, artifactVersion, forceUpdate ) )
{
return;
diff --git a/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java b/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java
index 0faeec399..f6e95f52d 100644
--- a/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java
+++ b/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java
@@ -126,6 +126,11 @@ private static ArtifactMetadataSource mockArtifactMetaDataSource() throws Artifa
new DefaultArtifactVersion( "1.0.0" ),
new DefaultArtifactVersion( "0.9.0" ) );
}
+ else if ( "issue-670-artifact".equals( artifact.getArtifactId() ) )
+ {
+ return Arrays.asList( new DefaultArtifactVersion( "0.0.1-1" ),
+ new DefaultArtifactVersion( "0.0.1-1-impl-SNAPSHOT" ) );
+ }
else if ( "unknown-artifact".equals( artifact.getArtifactId() ) )
{
return Collections.emptyList();
@@ -236,4 +241,51 @@ public void testParentDowngradeForbiddenWithRange()
}
assertThat( changeRecorder.getChanges(), is( empty() ) );
}
+
+ @Test
+ public void testAllowSnapshots()
+ throws MojoExecutionException, XMLStreamException, MojoFailureException
+ {
+ mojo.allowSnapshots = true;
+ mojo.getProject().setParent( new MavenProject()
+ {{
+ setGroupId( "default-group" );
+ setArtifactId( "issue-670-artifact" );
+ setVersion( "0.0.1-1" );
+ }} );
+
+ try ( MockedStatic pomHelper = mockStatic( PomHelper.class ) )
+ {
+ pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) )
+ .thenReturn( true );
+ mojo.update( null );
+ }
+ assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group",
+ "issue-670-artifact", "0.0.1-1",
+ "0.0.1-1-impl-SNAPSHOT" ) ) );
+ }
+
+ @Test
+ public void testAllowSnapshotsWithParentVersion()
+ throws MojoExecutionException, XMLStreamException, MojoFailureException
+ {
+ mojo.allowSnapshots = true;
+ mojo.parentVersion = "0.0.1-1-impl-SNAPSHOT";
+ mojo.getProject().setParent( new MavenProject()
+ {{
+ setGroupId( "default-group" );
+ setArtifactId( "issue-670-artifact" );
+ setVersion( "0.0.1-1" );
+ }} );
+
+ try ( MockedStatic pomHelper = mockStatic( PomHelper.class ) )
+ {
+ pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) )
+ .thenReturn( true );
+ mojo.update( null );
+ }
+ assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group",
+ "issue-670-artifact", "0.0.1-1",
+ "0.0.1-1-impl-SNAPSHOT" ) ) );
+ }
}