You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/10/19 13:38:50 UTC
(maven-dependency-plugin) 01/02: [MDEP-593] Add addImportedBoms to copy import-scoped BOM POMs
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 644b5a162287563a14e8161bbdced744b7c48601
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Oct 13 23:25:25 2026 +0200
[MDEP-593] Add addImportedBoms to copy import-scoped BOM POMs
---
.../mdep-593-copy-imported-boms/invoker.properties | 18 ++++
.../projects/mdep-593-copy-imported-boms/pom.xml | 94 +++++++++++++++++++
.../maven/its/mdep593/bom-a/1.0/bom-a-1.0.pom | 41 ++++++++
.../maven/its/mdep593/bom-b/1.0/bom-b-1.0.pom | 32 +++++++
.../maven/its/mdep593/bom-c/1.0/bom-c-1.0.pom | 27 ++++++
.../its/mdep593/bom-parent/1.0/bom-parent-1.0.pom | 27 ++++++
.../mdep593/grandparent/1.0/grandparent-1.0.pom | 27 ++++++
.../its/mdep593/lib-parent/1.0/lib-parent-1.0.pom | 46 +++++++++
.../apache/maven/its/mdep593/lib/1.0/lib-1.0.jar | Bin 0 -> 318 bytes
.../apache/maven/its/mdep593/lib/1.0/lib-1.0.pom | 29 ++++++
.../mdep-593-copy-imported-boms/setup.groovy | 22 +++++
.../mdep-593-copy-imported-boms/verify.groovy | 30 ++++++
.../AbstractDependencyFilterMojo.java | 103 +++++++++++++++++++++
.../fromDependencies/CopyDependenciesMojo.java | 14 ++-
.../TestCopyDependenciesMojo2.java | 29 ++++++
15 files changed, 538 insertions(+), 1 deletion(-)
diff --git a/src/it/projects/mdep-593-copy-imported-boms/invoker.properties b/src/it/projects/mdep-593-copy-imported-boms/invoker.properties
new file mode 100644
index 00000000..a644cb7e
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = clean package
diff --git a/src/it/projects/mdep-593-copy-imported-boms/pom.xml b/src/it/projects/mdep-593-copy-imported-boms/pom.xml
new file mode 100644
index 00000000..ccfa1843
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+ -->
+
+<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.apache.maven.its.dependency</groupId>
+ <artifactId>mdep-593</artifactId>
+ <version>1.0</version>
+ <description>
+ MDEP-593: addImportedBoms also copies the POMs of import-scoped BOMs, from the project and from the parents
+ of its dependencies, together with the parents and imports of those BOMs.
+ </description>
+ <repositories>
+ <repository>
+ <!-- Not mirrored by mrm, see src/it/mrm/settings.xml. -->
+ <id>fake-remote-repository</id>
+ <url>file:///${basedir}/repo/</url>
+ <releases>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-c</artifactId>
+ <version>1.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>lib</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <useRepositoryLayout>true</useRepositoryLayout>
+ <copyPom>true</copyPom>
+ <addParentPoms>true</addParentPoms>
+ </configuration>
+ <executions>
+ <execution>
+ <id>parents-only</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/parents-only</outputDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>with-boms</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/with-boms</outputDirectory>
+ <addImportedBoms>true</addImportedBoms>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-a/1.0/bom-a-1.0.pom b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-a/1.0/bom-a-1.0.pom
new file mode 100644
index 00000000..374228a4
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-a/1.0/bom-a-1.0.pom
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+-->
+<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.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-a</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+ <properties>
+ <bom.version>1.0</bom.version>
+ </properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-b</artifactId>
+ <version>${bom.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-b/1.0/bom-b-1.0.pom b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-b/1.0/bom-b-1.0.pom
new file mode 100644
index 00000000..441ee608
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-b/1.0/bom-b-1.0.pom
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+-->
+<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>
+ <parent>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-parent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-b</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-c/1.0/bom-c-1.0.pom b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-c/1.0/bom-c-1.0.pom
new file mode 100644
index 00000000..cd91f82d
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-c/1.0/bom-c-1.0.pom
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+-->
+<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.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-c</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-parent/1.0/bom-parent-1.0.pom b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-parent/1.0/bom-parent-1.0.pom
new file mode 100644
index 00000000..948aec28
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/bom-parent/1.0/bom-parent-1.0.pom
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+-->
+<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.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-parent</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/grandparent/1.0/grandparent-1.0.pom b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/grandparent/1.0/grandparent-1.0.pom
new file mode 100644
index 00000000..95e898eb
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/grandparent/1.0/grandparent-1.0.pom
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+-->
+<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.apache.maven.its.mdep593</groupId>
+ <artifactId>grandparent</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib-parent/1.0/lib-parent-1.0.pom b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib-parent/1.0/lib-parent-1.0.pom
new file mode 100644
index 00000000..ba282e30
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib-parent/1.0/lib-parent-1.0.pom
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+-->
+<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>
+ <parent>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>grandparent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>lib-parent</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+ <properties>
+ <bom.version>1.0</bom.version>
+ </properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>bom-a</artifactId>
+ <version>${bom.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib/1.0/lib-1.0.jar b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib/1.0/lib-1.0.jar
new file mode 100644
index 00000000..fb6dc6a7
Binary files /dev/null and b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib/1.0/lib-1.0.jar differ
diff --git a/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib/1.0/lib-1.0.pom b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib/1.0/lib-1.0.pom
new file mode 100644
index 00000000..590ac06a
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/repo/org/apache/maven/its/mdep593/lib/1.0/lib-1.0.pom
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+-->
+<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>
+ <parent>
+ <groupId>org.apache.maven.its.mdep593</groupId>
+ <artifactId>lib-parent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>lib</artifactId>
+</project>
diff --git a/src/it/projects/mdep-593-copy-imported-boms/setup.groovy b/src/it/projects/mdep-593-copy-imported-boms/setup.groovy
new file mode 100644
index 00000000..f3f925e8
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/setup.groovy
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+// Remove the test artifacts from the local repository so that they are resolved from the file repository again.
+new File(localRepositoryPath, 'org/apache/maven/its/mdep593').deleteDir()
+return true
diff --git a/src/it/projects/mdep-593-copy-imported-boms/verify.groovy b/src/it/projects/mdep-593-copy-imported-boms/verify.groovy
new file mode 100644
index 00000000..dd320d92
--- /dev/null
+++ b/src/it/projects/mdep-593-copy-imported-boms/verify.groovy
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+def base = 'org/apache/maven/its/mdep593'
+def always = ["lib/1.0/lib-1.0.jar", "lib/1.0/lib-1.0.pom", "lib-parent/1.0/lib-parent-1.0.pom", "grandparent/1.0/grandparent-1.0.pom"]
+def boms = ["bom-a/1.0/bom-a-1.0.pom", // imported by lib-parent, a parent of the dependency, through ${bom.version}
+ "bom-b/1.0/bom-b-1.0.pom", // imported by bom-a
+ "bom-parent/1.0/bom-parent-1.0.pom", // parent of bom-b
+ "bom-c/1.0/bom-c-1.0.pom"] // imported by the project itself
+
+always.each { assert new File(basedir, "target/parents-only/${base}/${it}").isFile() : "Missing ${it} in parents-only" }
+boms.each { assert !new File(basedir, "target/parents-only/${base}/${it}").exists() : "Unexpected ${it} in parents-only" }
+(always + boms).each { assert new File(basedir, "target/with-boms/${base}/${it}").isFile() : "Missing ${it} in with-boms" }
+return true
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
index 92ad48d8..40db7392 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
@@ -26,6 +26,8 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.maven.RepositoryUtils;
@@ -308,6 +310,22 @@ public abstract class AbstractDependencyFilterMojo extends AbstractDependencyMoj
*/
protected DependencyStatusSets getDependencySets(boolean stopOnFailure, boolean includeParents)
throws MojoExecutionException {
+ return getDependencySets(stopOnFailure, includeParents, false);
+ }
+
+ /**
+ * Method creates filters and filters the projects dependencies. This method also transforms the dependencies if
+ * classifier is set. The dependencies are filtered in least specific to most specific order.
+ *
+ * @param stopOnFailure true to fail if artifacts can't be resolved false otherwise
+ * @param includeParents <code>true</code> if parents should be included or not <code>false</code>
+ * @param includeImportedBoms <code>true</code> if the import-scoped BOMs of the project and of the parents should
+ * be included or not <code>false</code>
+ * @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
+ * @throws MojoExecutionException in case of errors
+ */
+ protected DependencyStatusSets getDependencySets(
+ boolean stopOnFailure, boolean includeParents, boolean includeImportedBoms) throws MojoExecutionException {
// add filters in well known order, least specific to most specific
FilterArtifacts filter = new FilterArtifacts();
@@ -359,6 +377,12 @@ public abstract class AbstractDependencyFilterMojo extends AbstractDependencyMoj
// add current project parent
addParentArtifacts(getProject(), parentArtifacts);
}
+ if (includeImportedBoms) {
+ for (Artifact dep : artifacts) {
+ addImportedBomArtifacts(buildProjectFromArtifact(dep), parentArtifacts, new HashSet<>());
+ }
+ addImportedBomArtifacts(getProject(), parentArtifacts, new HashSet<>());
+ }
// perform filtering
try {
@@ -423,6 +447,85 @@ public abstract class AbstractDependencyFilterMojo extends AbstractDependencyMoj
return new ClassifierTypeTranslator(artifactHandlerManager, this.classifier, this.type);
}
+ /**
+ * Adds the POMs of the BOMs that the project and its parents import in their dependencyManagement, together with
+ * the parents and imports of those BOMs. The effective model no longer lists the import-scoped entries, so they are
+ * read from the original models.
+ */
+ private void addImportedBomArtifacts(MavenProject project, Set<Artifact> artifacts, Set<String> visited)
+ throws MojoExecutionException {
+ for (MavenProject current = project; current != null; current = current.getParent()) {
+ if (current.getOriginalModel().getDependencyManagement() == null) {
+ continue;
+ }
+ for (Dependency managed :
+ current.getOriginalModel().getDependencyManagement().getDependencies()) {
+ if (!Artifact.SCOPE_IMPORT.equals(managed.getScope()) || !"pom".equals(managed.getType())) {
+ continue;
+ }
+ String groupId = interpolate(managed.getGroupId(), project);
+ String artifactId = interpolate(managed.getArtifactId(), project);
+ String version = interpolate(managed.getVersion(), project);
+ if (groupId.contains("${") || artifactId.contains("${") || version.contains("${")) {
+ getLog().warn("Skipping imported BOM " + managed.getManagementKey() + ":" + managed.getVersion()
+ + " of " + current.getId() + ", its coordinates cannot be interpolated.");
+ continue;
+ }
+ if (!visited.add(groupId + ':' + artifactId + ':' + version)) {
+ continue;
+ }
+ try {
+ org.eclipse.aether.artifact.Artifact resolvedBom = resolverUtil.resolveArtifact(
+ new org.eclipse.aether.artifact.DefaultArtifact(groupId, artifactId, "pom", version),
+ project.getRemoteProjectRepositories());
+ Artifact bomArtifact = RepositoryUtils.toArtifact(resolvedBom);
+ artifacts.add(bomArtifact);
+
+ MavenProject bomProject = buildProjectFromArtifact(bomArtifact);
+ addParentArtifacts(bomProject, artifacts);
+ addImportedBomArtifacts(bomProject, artifacts, visited);
+ } catch (ArtifactResolutionException | ArtifactDescriptorException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ String interpolate(String value, MavenProject project) {
+ if (value == null) {
+ return "";
+ }
+ Matcher matcher = Pattern.compile("\\$\\{([^}]+)}").matcher(value);
+ StringBuffer result = new StringBuffer();
+ while (matcher.find()) {
+ String key = matcher.group(1);
+ String replacement;
+ switch (key) {
+ case "project.groupId":
+ case "pom.groupId":
+ replacement = project.getGroupId();
+ break;
+ case "project.artifactId":
+ case "pom.artifactId":
+ replacement = project.getArtifactId();
+ break;
+ case "project.version":
+ case "pom.version":
+ replacement = project.getVersion();
+ break;
+ default:
+ replacement = session.getUserProperties().getProperty(key);
+ if (replacement == null) {
+ replacement = project.getProperties().getProperty(key);
+ }
+ }
+ matcher.appendReplacement(
+ result, Matcher.quoteReplacement(replacement != null ? replacement : matcher.group()));
+ }
+ matcher.appendTail(result);
+ return result.toString();
+ }
+
/**
* Transform artifacts.
*
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
index c12d7287..ed44b939 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
@@ -94,6 +94,17 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
@Parameter(property = "mdep.addParentPoms", defaultValue = "false")
protected boolean addParentPoms;
+ /**
+ * Add the POMs of the BOMs that the project and its parents import with {@code <scope>import</scope>} in their
+ * {@code dependencyManagement} (and of the parents and imports of those BOMs) to the list of copied dependencies,
+ * so that the copied POMs stay resolvable. Use it together with {@link #addParentPoms}; it is a separate parameter
+ * so that the output of {@code addParentPoms} does not change. Inclusion and exclusion filters still apply.
+ *
+ * @since 3.12.0
+ */
+ @Parameter(property = "mdep.addImportedBoms", defaultValue = "false")
+ protected boolean addImportedBoms;
+
/**
* Also copy the signature files (.asc) of each artifact.
*
@@ -124,7 +135,8 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
*/
@Override
protected void doExecute() throws MojoExecutionException {
- DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms);
+ DependencyStatusSets dss =
+ getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms, addImportedBoms);
Set<Artifact> artifacts = dss.getResolvedDependencies();
if (!useRepositoryLayout) {
diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java
index 2cde33e2..95def502 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java
@@ -55,6 +55,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@MojoTest(realRepositorySession = true)
@@ -301,6 +302,34 @@ class TestCopyDependenciesMojo2 {
assertTrue(Files.isRegularFile(artifactDirectory.resolve("artifact-with-project-pom-1.0.pom")));
}
+ @Test
+ @InjectMojo(goal = "copy-dependencies")
+ void testAddImportedBomsIsOffByDefault(CopyDependenciesMojo mojo) {
+ assertFalse(mojo.addImportedBoms);
+ }
+
+ @Test
+ @InjectMojo(goal = "copy-dependencies")
+ @MojoParameter(name = "addImportedBoms", value = "true")
+ void testAddImportedBomsParameter(CopyDependenciesMojo mojo) {
+ assertTrue(mojo.addImportedBoms);
+ }
+
+ @Test
+ @InjectMojo(goal = "copy-dependencies")
+ void testInterpolateImportedBomCoordinates(CopyDependenciesMojo mojo) {
+ MavenProject owner = mojo.getProject();
+ owner.setGroupId("g");
+ owner.setArtifactId("a");
+ owner.setVersion("2.0");
+ owner.getProperties().setProperty("bom.version", "1.5");
+
+ assertEquals("1.5", mojo.interpolate("${bom.version}", owner));
+ assertEquals("g:a:2.0", mojo.interpolate("${project.groupId}:${project.artifactId}:${project.version}", owner));
+ assertEquals("1.5-${unknown}", mojo.interpolate("${bom.version}-${unknown}", owner));
+ assertEquals("", mojo.interpolate(null, owner));
+ }
+
private Artifact createExpandedVersionArtifact(
String baseVersion, String groupId, String artifactId, String scope, String type, String classifier)
throws IOException {