Skip to content

Commit

Permalink
Set project.originalModel after flattening
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
clayreimann committed May 31, 2022
1 parent f02b2ad commit 0480708
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@
<goal>${project.groupId}:${project.artifactId}:${project.version}:flatten -Drevision=1.2.3.4</goal>
</goals>
<projectsDirectory>src/it/projects</projectsDirectory>
<postBuildHookScript>verify</postBuildHookScript>
<preBuildHookScript>setup</preBuildHookScript>
<postBuildHookScript>verify</postBuildHookScript>
<streamLogsOnFailures>true</streamLogsOnFailures>
</configuration>
</plugin>
<plugin>
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions src/it/projects/flatten-shaded-drp/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=package
103 changes: 103 additions & 0 deletions src/it/projects/flatten-shaded-drp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>flatten-shaded-drp</artifactId>
<version>0.0.1${rev}-SNAPSHOT</version>

<properties>
<flatten.its.version>3.2.1</flatten.its.version>
<rev></rev>
</properties>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>2.5</version>
</dependency>
</dependencies>

<build>
<defaultGoal>package</defaultGoal>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>ossrh</flattenMode>
<embedBuildProfileDependencies>true</embedBuildProfileDependencies>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>prepare-package</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>true</createDependencyReducedPom>
<artifactSet>
<includes>
<include>com.google.guava:*</include>
</includes>
</artifactSet>
</configuration>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<!-- should be removed -->
<profiles>
<profile>
<id>foo</id>
<activation>
<property>
<name>willNotBeActive</name>
</property>
</activation>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>core</artifactId>
<version>${flatten.its.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>

<pluginRepositories>
<pluginRepository>
<id>no-one</id>
<url>@repository.proxy.url@</url>
</pluginRepository>
</pluginRepositories>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example;

import java.util.List;
import com.google.common.collect.ImmutableList;
import org.apache.maven.archiver.MavenArchiver;

public class Main {
public static void main(String[] args) {
List<Object> l = ImmutableList.of();
MavenArchiver a = new MavenArchiver();
}
}
38 changes: 38 additions & 0 deletions src/it/projects/flatten-shaded-drp/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 originalPom = new File( basedir, 'pom.xml' )
assert originalPom.exists()

def originalProject = new XmlSlurper().parse( originalPom )
assert 1 == originalProject.dependencies.size()
assert 2 == originalProject.dependencies.dependency.size()

File flattendPom = new File( basedir, 'dependency-reduced-pom.xml' )
assert flattendPom.exists()

def flattendProject = new XmlSlurper().parse( flattendPom )
assert 1 == flattendProject.dependencies.size()
assert 1 == flattendProject.dependencies.dependency.size()

def archiver = flattendProject.dependencies.dependency.find {
it.groupId == 'org.apache.maven' && it.artifactId == 'maven-archiver'
}
assert '2.5' == archiver.version.text()
assert 'compile' == archiver.scope.text()

1 change: 1 addition & 0 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public void execute()
if ( isUpdatePomFile() )
{
this.project.setPomFile( flattenedPomFile );
this.project.setOriginalModel( flattenedPom );
}
}

Expand Down

0 comments on commit 0480708

Please sign in to comment.