diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 26ace56496c0..931e8c5bd379 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -28,7 +28,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -464,12 +463,7 @@ void performFor(String value, String locationKey, Consumer mutator) { } } } - HashSet profileIds = new HashSet<>(); for (Profile profile : interpolatedActivations) { - if (!profileIds.add(profile.getId())) { - problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE) - .setMessage("Duplicate activation for profile " + profile.getId())); - } Activation activation = profile.getActivation(); Optional a = Optional.ofNullable(activation); a.map(Activation::getFile).ifPresent(fa -> { 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 dc544d455cc9..1f1a7ab57242 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 @@ -95,6 +95,7 @@ public DefaultModelValidator(ModelVersionProcessor versionProcessor) { this.versionProcessor = versionProcessor; } + @SuppressWarnings("checkstyle:methodlength") @Override public void validateRawModel(Model m, ModelBuildingRequest request, ModelProblemCollector problems) { Parent parent = m.getParent(); @@ -132,7 +133,22 @@ public void validateRawModel(Model m, ModelBuildingRequest request, ModelProblem } } - if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) { + if (request.getValidationLevel() == ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL) { + // profiles: they are essential for proper model building (may contribute profiles, dependencies...) + HashSet minProfileIds = new HashSet<>(); + for (Profile profile : m.getProfiles()) { + if (!minProfileIds.add(profile.getId())) { + addViolation( + problems, + Severity.WARNING, + Version.BASE, + "profiles.profile.id", + null, + "Duplicate activation for profile " + profile.getId(), + profile); + } + } + } else if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) { Severity errOn30 = getSeverity(request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0); // [MNG-6074] Maven should produce an error if no model version has been set in a POM file used to build an