diff --git a/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/parent/pom.xml b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/parent/pom.xml
new file mode 100644
index 00000000..eae41161
--- /dev/null
+++ b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/parent/pom.xml
@@ -0,0 +1,23 @@
+
+ 4.0.0
+ org.codehaus.mojo.flatten.its
+ profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile_parent
+ 0.1-SNAPSHOT
+ pom
+
+
+ 1.3.2
+
+
+
+
+
+ javax.annotation
+ javax.annotation-api
+ ${javax.annotations.version}
+
+
+
+
diff --git a/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/pom.xml b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/pom.xml
new file mode 100644
index 00000000..9d93fc3b
--- /dev/null
+++ b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/pom.xml
@@ -0,0 +1,42 @@
+
+ 4.0.0
+ org.codehaus.mojo.flatten.its
+ profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile
+ 0.1-SNAPSHOT
+ jar
+
+ org.codehaus.mojo.flatten.its
+ profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile_parent
+ 0.1-SNAPSHOT
+ parent
+
+
+
+
+ org.codehaus.mojo
+ flatten-maven-plugin
+
+ true
+
+
+
+
+
+
+
+ java9
+
+ [1.9,)
+
+
+
+ javax.annotation
+ javax.annotation-api
+ true
+
+
+
+
+
diff --git a/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/verify.groovy b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/verify.groovy
new file mode 100644
index 00000000..621d44a9
--- /dev/null
+++ b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-optional-in-profile/verify.groovy
@@ -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()
diff --git a/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/parent/pom.xml b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/parent/pom.xml
new file mode 100644
index 00000000..7f8d372d
--- /dev/null
+++ b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/parent/pom.xml
@@ -0,0 +1,23 @@
+
+ 4.0.0
+ org.codehaus.mojo.flatten.its
+ profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile_parent
+ 0.1-SNAPSHOT
+ pom
+
+
+ 1.3.2
+
+
+
+
+
+ javax.annotation
+ javax.annotation-api
+ ${javax.annotations.version}
+
+
+
+
diff --git a/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/pom.xml b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/pom.xml
new file mode 100644
index 00000000..6500d9e0
--- /dev/null
+++ b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/pom.xml
@@ -0,0 +1,42 @@
+
+ 4.0.0
+ org.codehaus.mojo.flatten.its
+ profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile
+ 0.1-SNAPSHOT
+ jar
+
+ org.codehaus.mojo.flatten.its
+ profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile_parent
+ 0.1-SNAPSHOT
+ parent
+
+
+
+
+ org.codehaus.mojo
+ flatten-maven-plugin
+
+ true
+
+
+
+
+
+
+
+ java9
+
+ [1.9,)
+
+
+
+ javax.annotation
+ javax.annotation-api
+ provided
+
+
+
+
+
diff --git a/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/verify.groovy b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/verify.groovy
new file mode 100644
index 00000000..171d71bf
--- /dev/null
+++ b/src/it/projects/profile-with-deps-inherit-parent-depMgmt-jdk-scope-in-profile/verify.groovy
@@ -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()
diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
index ffc37a09..bf764dce 100644
--- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
+++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
@@ -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" );