diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 1523e969ae..a2ad5223e5 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -290,7 +290,14 @@ public class DefaultMavenProjectBuilder // Always cache files in the source tree over those in the repository MavenProject p = new MavenProject( model ); p.setFile( projectDescriptor ); - modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), p ); + + String modelKey = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ); + if ( modelCache.containsKey( modelKey ) ) + { + throw new ProjectBuildingException( model.getGroupId() + ":" + model.getArtifactId(), + "Duplicate project ID found in " + projectDescriptor.getAbsolutePath() ); + } + modelCache.put( modelKey, p ); MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository, buildArtifactRepositories( getSuperModel() ), @@ -852,6 +859,12 @@ public class DefaultMavenProjectBuilder { throw new ProjectBuildingException( projectId, "Missing artifactId element from parent element" ); } + else if ( parentModel.getGroupId().equals( model.getGroupId() ) && + parentModel.getArtifactId().equals( model.getArtifactId() ) ) + { + throw new ProjectBuildingException( projectId, "Parent element is a duplicate of " + + "the current project " ); + } else if ( StringUtils.isEmpty( parentModel.getVersion() ) ) { throw new ProjectBuildingException( projectId, "Missing version element from parent element" ); diff --git a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index 34e38b70aa..df1e04ec4d 100644 --- a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -21,6 +21,7 @@ import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Model; +import org.apache.maven.model.Parent; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.Reporting; @@ -60,6 +61,16 @@ public class DefaultModelValidator result.addMessage( "Packaging '" + model.getPackaging() + "' is invalid. Aggregator projects " + "require 'pom' as packaging." ); } + + Parent parent = model.getParent(); + if ( parent != null ) + { + if ( parent.getGroupId().equals( model.getGroupId() ) && + parent.getArtifactId().equals( model.getArtifactId() ) ) + { + result.addMessage( "The parent element cannot have the same ID as the project." ); + } + } validateStringNotEmpty( "version", result, model.getVersion() );