diff --git a/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java b/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java index 68893603f3..46db1a384a 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 0faeec3993..f6e95f52da 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" ) ) ); + } }