Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #291 Use scope/optional of profile dep over default #296

Merged
merged 1 commit into from Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,23 @@
<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-deps-inherit-parent-depMgmt-jdk-optional-in-profile_parent</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<javax.annotations.version>1.3.2</javax.annotations.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotations.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
@@ -0,0 +1,42 @@
<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-deps-inherit-parent-depMgmt-jdk-optional-in-profile</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile_parent</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>parent</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<embedBuildProfileDependencies>true</embedBuildProfileDependencies>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java9</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
@@ -0,0 +1,35 @@
/*
* 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 'java9' == 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 0 == flattendProject.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'javax.annotation-api' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.3.2' == flattendProject.profiles.profile.dependencies.dependency.version.text()
assert 'true' == flattendProject.profiles.profile.dependencies.dependency.optional.text()
@@ -0,0 +1,23 @@
<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-deps-inherit-parent-depMgmt-jdk-scope-in-profile_parent</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<javax.annotations.version>1.3.2</javax.annotations.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotations.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
@@ -0,0 +1,42 @@
<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-deps-inherit-parent-depMgmt-jdk-scope-in-profile</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile_parent</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>parent</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<embedBuildProfileDependencies>true</embedBuildProfileDependencies>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java9</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
@@ -0,0 +1,35 @@
/*
* 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 'java9' == 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 0 == flattendProject.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'javax.annotation-api' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.3.2' == flattendProject.profiles.profile.dependencies.dependency.version.text()
assert 'provided' == flattendProject.profiles.profile.dependencies.dependency.scope.text()
12 changes: 10 additions & 2 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Expand Up @@ -692,12 +692,20 @@ protected Model createCleanPom( Model effectivePom ) throws MojoExecutionExcepti
if ( managedDependencies.contains( parsedDep ) )
{
parsedDep.setVersion( managedDependencies.resolve( parsedDep ).getVersion() );
parsedDep.setScope( managedDependencies.resolve( parsedDep ).getScope() );
String managedDepScope = managedDependencies.resolve( parsedDep ).getScope();
if ( managedDepScope != null )
{
parsedDep.setScope( managedDepScope );
}
if ( parsedDep.getScope() == null )
{
parsedDep.setScope( "compile" );
}
parsedDep.setOptional( managedDependencies.resolve( parsedDep ).getOptional() );
String managedDepOptional = managedDependencies.resolve( parsedDep ).getOptional();
if ( managedDepOptional != null )
{
parsedDep.setOptional( managedDepOptional );
}
if ( parsedDep.getOptional() == null )
{
parsedDep.setOptional( "false" );
Expand Down