From e4b53d3f2c00e00d78129e20e177399a12d27847 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 18 Oct 2018 23:34:30 +0200 Subject: [PATCH] [MNG-6490] Maven shall not fail reporting circular dependency when the dependency is a classified secondary artifact --- .../validation/DefaultModelValidator.java | 22 +++++------ .../validation/DefaultModelValidatorTest.java | 7 ++++ .../raw-model/self-referencing-classifier.xml | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing-classifier.xml diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index 4018618f9b0..1c847767841 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -546,21 +546,21 @@ private void validate20RawDependenciesSelfReferencing( ModelProblemCollector pro List dependencies, String prefix, ModelBuildingRequest request ) { - // We only check for groupId/artifactId cause if there is another - // module with the same groupId/artifactId this will fail the build + // We only check for groupId/artifactId/version/classifier cause if there is another + // module with the same groupId/artifactId/version/classifier this will fail the build // earlier like "Project '...' is duplicated in the reactor. - // So it is sufficient to check only groupId/artifactId and not the + // So it is sufficient to check only groupId/artifactId/version/classifier and not the // packaging type. for ( Dependency dependency : dependencies ) { - String key = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion(); + String key = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion() + + ( dependency.getClassifier() != null ? ":" + dependency.getClassifier() : "" ); String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion(); if ( key.equals( mKey ) ) { // This means a module which is build has a dependency which has the same - // groupId, artifactId and version coordinates. This is in consequence - // a self reference or in other words a circular reference which can not - // being resolved. + // groupId, artifactId, version and classifier coordinates. This is in consequence + // a self reference or in other words a circular reference which can not being resolved. addViolation( problems, Severity.FATAL, Version.V31, prefix + " " + key, key, "is referencing itself.", dependency ); @@ -605,14 +605,14 @@ private void validateEffectiveDependencies( ModelProblemCollector problems, Mode private void validateEffectiveModelAgainstDependency( String prefix, ModelProblemCollector problems, Model m, Dependency d, ModelBuildingRequest request ) { - String key = d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion(); + String key = d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion() + + ( d.getClassifier() != null ? ":" + d.getClassifier() : "" ); String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion(); if ( key.equals( mKey ) ) { // This means a module which is build has a dependency which has the same - // groupId, artifactId and version coordinates. This is in consequence - // a self reference or in other words a circular reference which can not - // being resolved. + // groupId, artifactId, version and classifier coordinates. This is in consequence + // a self reference or in other words a circular reference which can not being resolved. addViolation( problems, Severity.FATAL, Version.V31, prefix + " " + key, key, "is referencing itself.", d ); } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index b02e0d90b36..3f31526e8f5 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -729,6 +729,13 @@ public void testSelfReferencingDependencyInRawModel() } + public void testSelfReferencingDependencyWithClassifierInRawModel() throws Exception + { + SimpleProblemCollector result = validateRaw( "raw-model/self-referencing-classifier.xml" ); + + assertViolations( result, 0, 0, 0 ); + } + public void testCiFriendlySha1() throws Exception { diff --git a/maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing-classifier.xml b/maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing-classifier.xml new file mode 100644 index 00000000000..099e501a2cc --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing-classifier.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + com.example.group + testvalidpom + 0.0.1-SNAPSHOT + + + This will test if the module validator recognized that this dependency with classifier + is not the same as the module itself. + + + + com.example.group + testvalidpom + 0.0.1-SNAPSHOT + linux + + + \ No newline at end of file