Skip to content
/ maven Public
forked from apache/maven

Commit

Permalink
Merge pull request apache#139 from lafoletc/profile-with-dependencies…
Browse files Browse the repository at this point in the history
…-inherit-parent-dependencyManagement

Fix embedBuildProfileDependencies bug
  • Loading branch information
lasselindqvist authored Mar 29, 2020
2 parents 49e81a9 + 96180e6 commit 4e7d13b
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<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>profile-with-dependencies-inherit-parent-dependencyManagement_parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<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>profile-with-dependencies-inherit-parent-dependencyManagement</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>profile-with-dependencies-inherit-parent-dependencyManagement_parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>parent</relativePath>
</parent>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<embedBuildProfileDependencies>true</embedBuildProfileDependencies>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>myprofile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 0 == originalProject.dependencies.size()
assert 'myprofile' == originalProject.profiles.profile.id.text()
assert 1 == originalProject.profiles.profile.dependencies.size()

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

def flattendProject = new XmlSlurper().parse( flattendPom )
assert 1 == flattendProject.dependencies.size()
assert 'dep' == flattendProject.dependencies.dependency.artifactId.text()
assert '1.1' == flattendProject.dependencies.dependency.version.text()
assert 0 == flattendProject.profiles.profile.size()
11 changes: 11 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/Dependencies.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public boolean contains( Dependency dependency )
return this.key2DependencyMap.containsKey( getKey( dependency ) );
}

/**
*
* @param dependency the {@link Dependency} to resolve.
* @return a full declared {@link Dependency}
*/
public Dependency resolve( Dependency dependency )
{
return this.key2DependencyMap.get( getKey( dependency ) );
}


/**
* @return a {@link List} with the {@link Dependency} objects contained in these {@link Dependencies}.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ protected List<Dependency> createFlattenedDependencies( Model effectiveModel )
// Non build-time driven profiles will remain in the flattened POM with their dependencies
// and
// allow dynamic dependencies due to OS or JDK.
flattenedDependencies.add( profileDependency );
flattenedDependencies.add( modelDependencies.resolve(profileDependency) );
}
}
}
Expand Down

0 comments on commit 4e7d13b

Please sign in to comment.