diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index a6e14e8f2f..9cee2425ac 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -180,7 +180,7 @@ public class DefaultMavenProjectBuilder addPluginsToModel(model, plugins); ProcessorContext.processManagementNodes(model); - + project = this.fromDomainModelToMavenProject(model, domainModel.getParentFile(), configuration, pomFile); ArrayList pln = new ArrayList(); @@ -194,13 +194,9 @@ public class DefaultMavenProjectBuilder Set pl = lifecycle.populateDefaultConfigurationForPlugins(new HashSet(pln), project, configuration.getLocalRepository()); /* - if(model.getArtifactId() != null && - model.getArtifactId().equals("maven-model")) - { - System.out.println(new DomainModel(project.getModel()).asString()); - } + */ - + for (Plugin buildPlugin : pl) { Xpp3Dom dom = (Xpp3Dom) buildPlugin.getConfiguration(); Plugin x = containsPlugin(buildPlugin, project.getModel() @@ -224,8 +220,14 @@ public class DefaultMavenProjectBuilder } } - project.getModel().getBuild().setPlugins(new ArrayList(pl)); - + project.getModel().getBuild().setPlugins(new ArrayList(pl)); + /* + if(model.getArtifactId() != null && + model.getArtifactId().equals("maven-model")) + { + System.out.println(new DomainModel(project.getModel()).asString()); + } + */ } catch (IOException e) { @@ -277,24 +279,35 @@ public class DefaultMavenProjectBuilder public static void addPluginsToModel(Model target, Set plugins) { - List mPlugins = new ArrayList(target.getBuild().getPlugins()); + List mngPlugins = (target.getBuild().getPluginManagement() != null) + ? target.getBuild().getPluginManagement().getPlugins() : new ArrayList(); + + List pomPlugins = new ArrayList(target.getBuild().getPlugins()); List lifecyclePlugins = new ArrayList(); for( Plugin p : plugins ) { - Plugin mPlugin = containsPlugin( p, mPlugins); - if( mPlugin == null) + //Go ahead and add version if exists in pluginManagement - don't use default version + Plugin mngPlugin = containsPlugin(p, mngPlugins); + if(mngPlugin != null && mngPlugin.getVersion() != null) + { + //System.out.println("Set version:" + p.getVersion() + ": To = " + mngPlugin.getVersion()); + p.setVersion(mngPlugin.getVersion()); + } + + Plugin pomPlugin = containsPlugin( p, pomPlugins); + if( pomPlugin == null) { lifecyclePlugins.add(p); } else if(p.getConfiguration() != null) { - System.out.println(Xpp3Dom.mergeXpp3Dom((Xpp3Dom) p.getConfiguration(), (Xpp3Dom) mPlugin.getConfiguration())); + System.out.println(Xpp3Dom.mergeXpp3Dom((Xpp3Dom) p.getConfiguration(), (Xpp3Dom) pomPlugin.getConfiguration())); } } - mPlugins.addAll(lifecyclePlugins); - target.getBuild().setPlugins(mPlugins); + pomPlugins.addAll(lifecyclePlugins); + target.getBuild().setPlugins(pomPlugins); } @@ -310,7 +323,7 @@ public class DefaultMavenProjectBuilder return null; } - + public MavenProject buildFromRepository(Artifact artifact, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException {