diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/invoker.properties b/versions-maven-plugin/src/it/it-update-properties-issue-837/invoker.properties
new file mode 100644
index 0000000000..b992cb3c77
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/invoker.properties
@@ -0,0 +1,2 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-properties
+invoker.mavenOpts = -DincludeParent=false
diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/parent-pom.xml b/versions-maven-plugin/src/it/it-update-properties-issue-837/parent-pom.xml
new file mode 100644
index 0000000000..d01abb3eec
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/parent-pom.xml
@@ -0,0 +1,14 @@
+
+ 4.0.0
+
+ default-group
+ parent-artifact
+ 1.0.0
+ pom
+
+
+ 1.0
+
+
+
diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/pom.xml b/versions-maven-plugin/src/it/it-update-properties-issue-837/pom.xml
new file mode 100644
index 0000000000..e80ba17a43
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/pom.xml
@@ -0,0 +1,23 @@
+
+ 4.0.0
+
+
+ default-group
+ parent-artifact
+ 1.0.0
+ parent-pom.xml
+
+
+ child-artifact
+ 1.0.0
+
+
+
+ localhost
+ dummy-api
+ ${artifact-version}
+
+
+
+
diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/verify.groovy b/versions-maven-plugin/src/it/it-update-properties-issue-837/verify.groovy
new file mode 100644
index 0000000000..5b4f858adb
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/verify.groovy
@@ -0,0 +1 @@
+assert ! ( new File( basedir, "build.log" ).text.contains( 'Property ${artifact-version}' ) )
diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/invoker.properties b/versions-maven-plugin/src/it/it-update-property-issue-837/invoker.properties
new file mode 100644
index 0000000000..3d5b27837c
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-property-issue-837/invoker.properties
@@ -0,0 +1,2 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-property
+invoker.mavenOpts = -DincludeParent=false -Dproperty=artifact-version
diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/parent-pom.xml b/versions-maven-plugin/src/it/it-update-property-issue-837/parent-pom.xml
new file mode 100644
index 0000000000..d01abb3eec
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-property-issue-837/parent-pom.xml
@@ -0,0 +1,14 @@
+
+ 4.0.0
+
+ default-group
+ parent-artifact
+ 1.0.0
+ pom
+
+
+ 1.0
+
+
+
diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/pom.xml b/versions-maven-plugin/src/it/it-update-property-issue-837/pom.xml
new file mode 100644
index 0000000000..e80ba17a43
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-property-issue-837/pom.xml
@@ -0,0 +1,23 @@
+
+ 4.0.0
+
+
+ default-group
+ parent-artifact
+ 1.0.0
+ parent-pom.xml
+
+
+ child-artifact
+ 1.0.0
+
+
+
+ localhost
+ dummy-api
+ ${artifact-version}
+
+
+
+
diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/verify.groovy b/versions-maven-plugin/src/it/it-update-property-issue-837/verify.groovy
new file mode 100644
index 0000000000..f60420cb94
--- /dev/null
+++ b/versions-maven-plugin/src/it/it-update-property-issue-837/verify.groovy
@@ -0,0 +1,2 @@
+assert ! ( new File( basedir, "build.log" ).text
+ .contains( 'Property ${artifact-version}: Set of valid available versions is [1.0, 1.0.1,' ) )
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java
index 5ce3f508ae..e4ff921dac 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java
@@ -493,6 +493,20 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A
return true;
}
+ /**
+ * Attempts to update the property to a newer version, if that exists
+ * @param pom pom to update
+ * @param property property to update
+ * @param version {@link PropertyVersions} object
+ * @param currentVersion current version
+ * @param allowDowngrade if downgrades should be allowed if snapshots are not allowed
+ * @param unchangedSegment most major segment not to be changed
+ * @return new version of the artifact, if the property was updated; {@code null} if there was no update
+ * @throws XMLStreamException thrown from {@link ModifiedPomXMLEventReader} if the update doesn't succeed
+ * @throws InvalidVersionSpecificationException thrown if {@code unchangedSegment} doesn't match the version
+ * @throws InvalidSegmentException thrown if {@code unchangedSegment} is invalid
+ * @throws MojoExecutionException thrown if any other error occurs
+ */
protected ArtifactVersion updatePropertyToNewestVersion( ModifiedPomXMLEventReader pom, Property property,
PropertyVersions version, String currentVersion,
boolean allowDowngrade,
@@ -511,9 +525,10 @@ protected ArtifactVersion updatePropertyToNewestVersion( ModifiedPomXMLEventRead
else if ( PomHelper.setPropertyVersion( pom, version.getProfileId(), property.getName(), winner.toString() ) )
{
getLog().info( "Updated ${" + property.getName() + "} from " + currentVersion + " to " + winner );
+ return winner;
}
- return winner;
+ return null;
}
/**
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
index 8292a6926d..129fb47559 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
@@ -133,6 +133,16 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo
defaultValue = "true" )
protected boolean allowIncrementalUpdates = true;
+ /**
+ *
Whether to include parent POMs in the search. Default: {@code true}
+ * Setting this to {@code false} can speed up execution, but will not resolve
+ * property-bound dependencies, defined in parent POMs.
+ *
+ * @since 2.14.0
+ */
+ @Parameter( property = "includeParent", defaultValue = "true" )
+ protected boolean includeParent = true;
+
// -------------------------- STATIC METHODS --------------------------
// -------------------------- OTHER METHODS --------------------------
@@ -164,6 +174,7 @@ protected void update( ModifiedPomXMLEventReader pom )
.withIncludeProperties( includeProperties )
.withExcludeProperties( excludeProperties )
.withAutoLinkItems( autoLinkItems )
+ .withIncludeParent( includeParent )
.build() );
for ( Map.Entry entry : propertyVersions.entrySet() )
{
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
index e8371fd369..ddfa296031 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
@@ -132,6 +132,16 @@ public class UpdatePropertyMojo
@Parameter( property = "allowIncrementalUpdates", defaultValue = "true" )
protected boolean allowIncrementalUpdates;
+ /**
+ * Whether to include parent POMs in the search. Default: {@code true}
+ * Setting this to {@code false} can speed up execution, but will not resolve
+ * property-bound dependencies, defined in parent POMs.
+ *
+ * @since 2.14.0
+ */
+ @Parameter( property = "includeParent", defaultValue = "true" )
+ protected boolean includeParent = true;
+
// -------------------------- STATIC METHODS --------------------------
// -------------------------- OTHER METHODS --------------------------
@@ -165,6 +175,7 @@ protected void update( ModifiedPomXMLEventReader pom )
.withPropertyDefinitions( new Property[] {propertyConfig} )
.withIncludeProperties( property )
.withAutoLinkItems( autoLinkItems )
+ .withIncludeParent( includeParent )
.build() );
for ( Map.Entry entry : propertyVersions.entrySet() )
{
diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java
index 62c034b105..2da6749d03 100644
--- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java
+++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java
@@ -22,11 +22,15 @@
import java.nio.file.Paths;
import org.codehaus.mojo.versions.change.DefaultVersionChange;
-import org.hamcrest.Matchers;
+import org.codehaus.mojo.versions.utils.TestChangeRecorder;
+import org.codehaus.mojo.versions.utils.TestUtils;
import org.junit.Test;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.is;
/**
* Unit tests for {@link UpdatePropertiesMojo}
@@ -39,7 +43,7 @@ public void testAllowMajorUpdates() throws Exception
Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/update-properties/issue-454-pom.xml" ),
Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING );
setUpMojo( "update-properties" ).execute();
- assertThat( changeRecorder.getChanges(), Matchers.hasItem(
+ assertThat( changeRecorder.getChanges(), hasItem(
new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "2.0.0-M1" ) ) );
}
@@ -51,7 +55,7 @@ public void testAllowMinorUpdates() throws Exception
UpdatePropertiesMojo mojo = setUpMojo( "update-properties" );
mojo.allowMajorUpdates = false;
mojo.execute();
- assertThat( changeRecorder.getChanges(), Matchers.hasItem(
+ assertThat( changeRecorder.getChanges(), hasItem(
new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.1.0-alpha" ) ) );
}
@@ -64,7 +68,23 @@ public void testAllowIncrementalUpdates() throws Exception
mojo.allowMajorUpdates = false;
mojo.allowMinorUpdates = false;
mojo.execute();
- assertThat( changeRecorder.getChanges(), Matchers.hasItem(
+ assertThat( changeRecorder.getChanges(), hasItem(
new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.0.1-rc1" ) ) );
}
+
+ @Test
+ public void testChangesNotRegisteredIfNoUpdatesInPom()
+ throws Exception
+ {
+ TestUtils.copyDir( Paths.get( "src/test/resources/org/codehaus/mojo/update-properties/issue-837" ),
+ pomDir );
+ UpdatePropertiesMojo mojo = setUpMojo( "update-properties" );
+ TestChangeRecorder changeRecorder = new TestChangeRecorder();
+ setVariableValueToObject( mojo, "changeRecorders", changeRecorder.asTestMap() );
+ setVariableValueToObject( mojo, "changeRecorderFormat", "none" );
+// pomHelperClass.when( () -> PomHelper.setPropertyVersion( any(), anyString(), anyString(), anyString() ) )
+// .thenReturn( false );
+ mojo.execute( );
+ assertThat( changeRecorder.getChanges(), is( empty() ) );
+ }
}
diff --git a/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/parent-pom.xml b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/parent-pom.xml
new file mode 100644
index 0000000000..d01abb3eec
--- /dev/null
+++ b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/parent-pom.xml
@@ -0,0 +1,14 @@
+
+ 4.0.0
+
+ default-group
+ parent-artifact
+ 1.0.0
+ pom
+
+
+ 1.0
+
+
+
diff --git a/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/pom.xml b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/pom.xml
new file mode 100644
index 0000000000..31c6622ece
--- /dev/null
+++ b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/pom.xml
@@ -0,0 +1,23 @@
+
+ 4.0.0
+
+
+ default-group
+ parent-artifact
+ 1.0.0
+ parent-pom.xml
+
+
+ child-artifact
+ 1.0.0
+
+
+
+ default-group
+ default-artifact
+ ${artifact-version}
+
+
+
+