diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index ed6b35c9de..f3c8bd0c47 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -1405,8 +1405,7 @@ public class PomConstructionTest { PomTestWrapper pom = buildPom( "dependency-scope-inheritance/sub" ); String scope = (String) pom.getValue("dependencies[1]/scope"); - assertNull("Scope not null: " + scope, scope); - + assertEquals( "compile", scope ); } public void testDependencyScope() diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java index d8b6973471..e1ab687612 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java @@ -175,6 +175,8 @@ public class DefaultModelBuilder managementInjector.injectManagement( resultModel, request ); + modelNormalizer.injectDefaultValues( resultModel, request ); + if ( request.isProcessPlugins() ) { pluginConfigurationExpander.expandPluginConfiguration( resultModel, request ); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultModelNormalizer.java b/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultModelNormalizer.java index e0536274b6..4f6027a628 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultModelNormalizer.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultModelNormalizer.java @@ -26,11 +26,13 @@ import java.util.List; import java.util.Map; import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.model.Plugin; import org.apache.maven.model.merge.MavenModelMerger; import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.util.StringUtils; /** * Handles normalization of a model. @@ -78,4 +80,30 @@ public class DefaultModelNormalizer } + public void injectDefaultValues( Model model, ModelBuildingRequest request ) + { + injectDependencyDefaults( model.getDependencies() ); + + Build build = model.getBuild(); + if ( build != null ) + { + for ( Plugin plugin : build.getPlugins() ) + { + injectDependencyDefaults( plugin.getDependencies() ); + } + } + } + + private void injectDependencyDefaults( List dependencies ) + { + for ( Dependency dependency : dependencies ) + { + if ( StringUtils.isEmpty( dependency.getScope() ) ) + { + // we cannot set this directly in the MDO due to the interactions with dependency management + dependency.setScope( "compile" ); + } + } + } + } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ModelNormalizer.java b/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ModelNormalizer.java index 1c685dbe72..c061c84645 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ModelNormalizer.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ModelNormalizer.java @@ -23,7 +23,8 @@ import org.apache.maven.model.Model; import org.apache.maven.model.ModelBuildingRequest; /** - * Handles normalization of a model. + * Handles normalization of a model. In this context, normalization is the process of producing a canonical + * representation for models that physically look different but are semantically equivalent. * * @author Benjamin Bentmann */ @@ -38,4 +39,13 @@ public interface ModelNormalizer */ void mergeDuplicates( Model model, ModelBuildingRequest request ); + /** + * Sets default values in the specified model that for technical reasons cannot be set directly in the Modello + * definition. + * + * @param model The model in which to set the default values, must not be {@code null}. + * @param request The model building request that holds further settings, must not be {@code null}. + */ + void injectDefaultValues( Model model, ModelBuildingRequest request ); + }