diff --git a/src/it/projects/MSHADE-323-compatible-with-flatten-pom/pom.xml b/src/it/projects/MSHADE-323-compatible-with-flatten-pom/pom.xml new file mode 100644 index 00000000..f4b66151 --- /dev/null +++ b/src/it/projects/MSHADE-323-compatible-with-flatten-pom/pom.xml @@ -0,0 +1,84 @@ + + + + + + 4.0.0 + + org.apache.maven.its.shade.flatten + test + 1.0 + + MSHADE-323 + + Test the integration of Shade and Flatten plugins. + + + + 0.1 + true + + + + + org.apache.maven.its.shade.drp + a + ${ver} + + + + + + + org.codehaus.mojo + flatten-maven-plugin + 1.2.5 + + + + flatten + + prepare-package + + + + + maven-jar-plugin + 3.2.2 + + + org.apache.maven.plugins + maven-shade-plugin + @project.version@ + + + + shade + + + true + target/dependency-reduced-pom.xml + + + + + + + diff --git a/src/it/projects/MSHADE-323-compatible-with-flatten-pom/src/main/java/A.java b/src/it/projects/MSHADE-323-compatible-with-flatten-pom/src/main/java/A.java new file mode 100644 index 00000000..3b244767 --- /dev/null +++ b/src/it/projects/MSHADE-323-compatible-with-flatten-pom/src/main/java/A.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +class A {} diff --git a/src/it/projects/MSHADE-323-compatible-with-flatten-pom/verify.groovy b/src/it/projects/MSHADE-323-compatible-with-flatten-pom/verify.groovy new file mode 100644 index 00000000..c715ed64 --- /dev/null +++ b/src/it/projects/MSHADE-323-compatible-with-flatten-pom/verify.groovy @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +File pomFile = new File( basedir, "target/dependency-reduced-pom.xml" ); +assert pomFile.isFile() + +def ns = new groovy.xml.Namespace( "http://maven.apache.org/POM/4.0.0" ) +def pom = new XmlParser().parse( pomFile ) + +assert pom.properties.size() == 0 diff --git a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java index d717253f..cfa6e3c4 100644 --- a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java +++ b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java @@ -25,6 +25,7 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.Exclusion; import org.apache.maven.model.Model; +import org.apache.maven.model.io.ModelReader; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; @@ -140,6 +141,12 @@ public class ShadeMojo @Component protected ArtifactResolver artifactResolver; + /** + * Model reader for parsing pom file + */ + @Component + private ModelReader modelReader; + /** * Artifacts to include/exclude from the final artifact. Artifacts are denoted by composite identifiers of the * general form groupId:artifactId:type:classifier. Since version 1.3, the wildcard characters '*' and @@ -481,7 +488,7 @@ public void execute() List resourceTransformers = getResourceTransformers(); - if ( createDependencyReducedPom ) + if ( createDependencyReducedPom && project.getFile() != null ) { createDependencyReducedPom( artifactIds ); @@ -1090,7 +1097,8 @@ private void createDependencyReducedPom( Set artifactsToRemove ) origDeps = transitiveDeps; } - Model model = project.getOriginalModel(); + final Model model = modelReader.read( project.getFile(), null ); + // MSHADE-185: We will remove all system scoped dependencies which usually // have some kind of property usage. At this time the properties within // such things are already evaluated.