From 10f409e3c837127e13867fe5fddcb16b93c84677 Mon Sep 17 00:00:00 2001 From: pazderski Date: Tue, 25 Aug 2020 00:38:08 +0200 Subject: [PATCH] [MNG-6983] Plugin key can get out of sync with artifactId and groupId The plugin key is build as combination of artifactId and groupId but not updated if either of these two ids change. This can be a problem if artifactId or groupId is a variable. The calculated key will likely contain the unresolved property and is not updated once the variable is interpolated. --- .../maven/project/ProjectBuilderTest.java | 14 +++++++ .../project-builder/MNG-6983/parent-pom.xml | 42 +++++++++++++++++++ .../projects/project-builder/MNG-6983/pom.xml | 22 ++++++++++ maven-model/src/main/mdo/maven.mdo | 8 +--- 4 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 maven-core/src/test/projects/project-builder/MNG-6983/parent-pom.xml create mode 100644 maven-core/src/test/projects/project-builder/MNG-6983/pom.xml diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java index 538f887b02d2..7cd3758d6237 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java @@ -36,6 +36,7 @@ import org.apache.maven.AbstractCoreMavenComponentTestCase; import org.apache.maven.artifact.InvalidArtifactRTException; import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; import org.apache.maven.model.building.FileModelSource; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelSource; @@ -330,4 +331,17 @@ public void testBuildProperties() assertEquals( 1, project.getMailingLists().size() ); assertEquals( 1, project.getResources().size() ); } + + public void testPropertyInPluginManagementGroupId() + throws Exception + { + File pom = getProject( "MNG-6983" ); + + MavenSession session = createMavenSession( pom ); + MavenProject project = session.getCurrentProject(); + + for (Plugin buildPlugin : project.getBuildPlugins()) { + assertNotNull( "Missing version for build plugin " + buildPlugin.getKey(), buildPlugin.getVersion() ); + } + } } diff --git a/maven-core/src/test/projects/project-builder/MNG-6983/parent-pom.xml b/maven-core/src/test/projects/project-builder/MNG-6983/parent-pom.xml new file mode 100644 index 000000000000..a1b9dbe6451f --- /dev/null +++ b/maven-core/src/test/projects/project-builder/MNG-6983/parent-pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + + org.example + parent + 0.0.1-SNAPSHOT + pom + + + 11 + 11 + UTF-8 + + org.codehaus.mojo + + + + + + + ${codehaus.group.id} + build-helper-maven-plugin + 3.2.0 + + + add-source-config + generate-sources + + add-source + + + + . + + + + + + + + + diff --git a/maven-core/src/test/projects/project-builder/MNG-6983/pom.xml b/maven-core/src/test/projects/project-builder/MNG-6983/pom.xml new file mode 100644 index 000000000000..913274684f13 --- /dev/null +++ b/maven-core/src/test/projects/project-builder/MNG-6983/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + + org.example + parent + 0.0.1-SNAPSHOT + ./parent-pom.xml + + + child + jar + + + + + ${codehaus.group.id} + build-helper-maven-plugin + + + + diff --git a/maven-model/src/main/mdo/maven.mdo b/maven-model/src/main/mdo/maven.mdo index 1f1f9d1864d9..7f439faa9f7d 100644 --- a/maven-model/src/main/mdo/maven.mdo +++ b/maven-model/src/main/mdo/maven.mdo @@ -2314,18 +2314,12 @@ return id.toString(); } - //TODO we shall reset key variable when groupId/artifactId change - private String key = null; /** * @return the key of the plugin, ie groupId:artifactId */ public String getKey() { - if ( key == null ) - { - key = constructKey( groupId, artifactId ); - } - return key; + return constructKey( groupId, artifactId ); } /**