Skip to content

Commit 971ae28

Browse files
clayreimannslawekjaranowski
authored andcommitted
Set project.originalModel after flattening
Based on the discussion in maven-shade-plugin#129 apache/maven-shade-plugin#129 (comment) It seems that the flatten plugin should update the `originalModel` property after we flatten the pom.
1 parent a940cb1 commit 971ae28

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=package
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.codehaus.mojo.flatten.its</groupId>
5+
<artifactId>flatten-shaded-drp</artifactId>
6+
<version>0.0.1${rev}-SNAPSHOT</version>
7+
8+
<properties>
9+
<flatten.its.version>3.2.1</flatten.its.version>
10+
<rev></rev>
11+
<maven.compiler.source>1.8</maven.compiler.source>
12+
<maven.compiler.target>1.8</maven.compiler.target>
13+
</properties>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.google.guava</groupId>
18+
<artifactId>guava</artifactId>
19+
<version>16.0.1</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.apache.maven</groupId>
23+
<artifactId>maven-archiver</artifactId>
24+
<version>2.5</version>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<defaultGoal>package</defaultGoal>
30+
31+
<plugins>
32+
<plugin>
33+
<groupId>org.codehaus.mojo</groupId>
34+
<artifactId>flatten-maven-plugin</artifactId>
35+
<configuration>
36+
<updatePomFile>true</updatePomFile>
37+
<flattenMode>ossrh</flattenMode>
38+
<embedBuildProfileDependencies>true</embedBuildProfileDependencies>
39+
</configuration>
40+
<executions>
41+
<execution>
42+
<id>flatten</id>
43+
<phase>prepare-package</phase>
44+
<goals>
45+
<goal>flatten</goal>
46+
</goals>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-shade-plugin</artifactId>
54+
<version>3.3.0</version>
55+
<configuration>
56+
<minimizeJar>true</minimizeJar>
57+
<createDependencyReducedPom>true</createDependencyReducedPom>
58+
<artifactSet>
59+
<includes>
60+
<include>com.google.guava:*</include>
61+
</includes>
62+
</artifactSet>
63+
</configuration>
64+
<executions>
65+
<execution>
66+
<id>shade</id>
67+
<phase>package</phase>
68+
<goals>
69+
<goal>shade</goal>
70+
</goals>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
77+
<!-- should be removed -->
78+
<profiles>
79+
<profile>
80+
<id>foo</id>
81+
<activation>
82+
<property>
83+
<name>willNotBeActive</name>
84+
</property>
85+
</activation>
86+
87+
<dependencies>
88+
<dependency>
89+
<groupId>org.codehaus.mojo.flatten.its</groupId>
90+
<artifactId>core</artifactId>
91+
<version>${flatten.its.version}</version>
92+
</dependency>
93+
</dependencies>
94+
</profile>
95+
</profiles>
96+
97+
<pluginRepositories>
98+
<pluginRepository>
99+
<id>no-one</id>
100+
<url>@repository.proxy.url@</url>
101+
</pluginRepository>
102+
</pluginRepositories>
103+
104+
105+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example;
2+
3+
import java.util.List;
4+
import com.google.common.collect.ImmutableList;
5+
import org.apache.maven.archiver.MavenArchiver;
6+
7+
public class Main {
8+
public static void main(String[] args) {
9+
List<Object> l = ImmutableList.of();
10+
MavenArchiver a = new MavenArchiver();
11+
}
12+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
File originalPom = new File( basedir, 'pom.xml' )
20+
assert originalPom.exists()
21+
22+
def originalProject = new XmlSlurper().parse( originalPom )
23+
assert 1 == originalProject.dependencies.size()
24+
assert 2 == originalProject.dependencies.dependency.size()
25+
26+
File flattendPom = new File( basedir, 'dependency-reduced-pom.xml' )
27+
assert flattendPom.exists()
28+
29+
def flattendProject = new XmlSlurper().parse( flattendPom )
30+
assert 1 == flattendProject.dependencies.size()
31+
assert 1 == flattendProject.dependencies.dependency.size()
32+
33+
def archiver = flattendProject.dependencies.dependency.find {
34+
it.groupId == 'org.apache.maven' && it.artifactId == 'maven-archiver'
35+
}
36+
assert '2.5' == archiver.version.text()
37+
assert 'compile' == archiver.scope.text()
38+
39+
assert 0 == flattendProject.build.size()
40+
assert 0 == flattendProject.profiles.size()
41+
assert 0 == flattendProject.pluginRepositories.size()

src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ public void execute()
422422
if ( isUpdatePomFile() )
423423
{
424424
this.project.setPomFile( flattenedPomFile );
425+
this.project.setOriginalModel( flattenedPom );
425426
}
426427
}
427428

0 commit comments

Comments
 (0)