Skip to content

Commit a742a88

Browse files
committed
Resolves #837: Add includeParent (default false) to UpdatePropertiesMojo
1 parent 9576c2e commit a742a88

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-properties
2+
invoker.mavenOpts = -DincludeParent=false
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>default-group</groupId>
6+
<artifactId>parent-artifact</artifactId>
7+
<version>1.0.0</version>
8+
<packaging>pom</packaging>
9+
10+
<properties>
11+
<artifact-version>1.0</artifact-version>
12+
</properties>
13+
14+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>default-group</groupId>
7+
<artifactId>parent-artifact</artifactId>
8+
<version>1.0.0</version>
9+
<relativePath>parent-pom.xml</relativePath>
10+
</parent>
11+
12+
<artifactId>child-artifact</artifactId>
13+
<version>1.0.0</version>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>localhost</groupId>
18+
<artifactId>dummy-api</artifactId>
19+
<version>${artifact-version}</version>
20+
</dependency>
21+
</dependencies>
22+
23+
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert ! ( new File( basedir, "build.log" ).text.contains( 'Property ${artifact-version}' ) )

versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.codehaus.mojo.versions.recording.DefaultChangeRecord;
4545
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
4646

47+
import static java.util.Optional.ofNullable;
4748
import static org.codehaus.mojo.versions.utils.SegmentUtils.determineUnchangedSegment;
4849

4950
/**
@@ -133,6 +134,16 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo
133134
defaultValue = "true" )
134135
protected boolean allowIncrementalUpdates = true;
135136

137+
/**
138+
* <p>Whether to include parent POMs in the search. Default: {@code true}</p>
139+
* <p>Setting this to {@code false} can speed up execution, but will not resolve
140+
* property-bound dependencies, defined in parent POMs.
141+
*
142+
* @since 2.14.0
143+
*/
144+
@Parameter( property = "includeParent", defaultValue = "true" )
145+
protected boolean includeParent = true;
146+
136147
// -------------------------- STATIC METHODS --------------------------
137148

138149
// -------------------------- OTHER METHODS --------------------------
@@ -164,6 +175,7 @@ protected void update( ModifiedPomXMLEventReader pom )
164175
.withIncludeProperties( includeProperties )
165176
.withExcludeProperties( excludeProperties )
166177
.withAutoLinkItems( autoLinkItems )
178+
.withIncludeParent( includeParent )
167179
.build() );
168180
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
169181
{
@@ -200,7 +212,7 @@ protected void update( ModifiedPomXMLEventReader pom )
200212
updatePropertyToNewestVersion( pom, property, version, currentVersion,
201213
allowDowngrade, unchangedSegment );
202214

203-
if ( targetVersion != null )
215+
if ( pom.isModified() )
204216
{
205217
for ( final ArtifactAssociation association : version.getAssociations() )
206218
{
@@ -211,7 +223,9 @@ protected void update( ModifiedPomXMLEventReader pom )
211223
ChangeRecord.ChangeKind.PROPERTY )
212224
.withArtifact( association.getArtifact() )
213225
.withOldVersion( currentVersion )
214-
.withNewVersion( targetVersion.toString() )
226+
.withNewVersion( ofNullable( targetVersion )
227+
.map( ArtifactVersion::toString )
228+
.orElse( "(empty)" ) )
215229
.build() );
216230
}
217231
}

0 commit comments

Comments
 (0)