diff --git a/README.md b/README.md
index 8c2fc91..2bf9d3a 100644
--- a/README.md
+++ b/README.md
@@ -110,6 +110,8 @@ Example usage:
runtime
+
+ DEPENDENCY_MANAGEMENT
diff --git a/pom.xml b/pom.xml
index fba9412..e0a7c57 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,6 +128,31 @@
+
+ org.apache.maven.plugins
+ maven-invoker-plugin
+ 3.2.2
+
+ ${project.build.directory}/it
+ true
+ src/it/settings.xml
+ ${project.build.directory}/local-repo
+
+ */pom.xml
+
+ src/it
+ verify
+
+
+
+ run-invoker
+
+ run
+
+ integration-test
+
+
+
diff --git a/src/it/dependencies-pom/pom.xml b/src/it/dependencies-pom/pom.xml
new file mode 100644
index 0000000..3821450
--- /dev/null
+++ b/src/it/dependencies-pom/pom.xml
@@ -0,0 +1,72 @@
+
+
+
+
+ 4.0.0
+
+ org.wildfly.plugins.test
+ dependencies-pom
+ @pom.version@
+
+
+ UTF-8
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.14.0
+
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.14.0
+
+
+
+
+
+
+
+ org.wildfly.plugins
+ wildfly-bom-builder-plugin
+ @pom.version@
+
+
+ build-bom
+
+ build-bom
+
+
+
+
+ org.wildfly.plugins.test
+ dependencies-pom
+ $@pom.version@
+
+
+
+
+
+
diff --git a/src/it/dependencies-pom/verify.groovy b/src/it/dependencies-pom/verify.groovy
new file mode 100644
index 0000000..cb823a7
--- /dev/null
+++ b/src/it/dependencies-pom/verify.groovy
@@ -0,0 +1,33 @@
+/*
+ ~ Copyright (C) 2013 Red Hat, Inc
+ ~
+ ~ Licensed 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 file = new File(basedir, "target/bom-pom.xml")
+def line
+def foundDependency = false
+file.withReader { reader ->
+ while ((line = reader.readLine())!=null) {
+ if (line.contains("commons-lang3")) {
+ foundDependency = true
+ break
+ }
+ }
+}
+if (!foundDependency) {
+ println("VERIFY ERROR: bom-pom.xml does not contain commons-lang3 dependency!")
+ return false
+}
+
+
diff --git a/src/it/dependency-management-pom/pom.xml b/src/it/dependency-management-pom/pom.xml
new file mode 100644
index 0000000..350a588
--- /dev/null
+++ b/src/it/dependency-management-pom/pom.xml
@@ -0,0 +1,88 @@
+
+
+
+
+ 4.0.0
+
+ @pom.groupId@
+ dependency-management-pom
+ @pom.version@
+
+
+ UTF-8
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.14.0
+
+
+ org.apache.commons
+ commons-text
+ 1.12.0
+ provided
+
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+ org.apache.commons
+ commons-text
+
+
+
+
+
+
+ org.wildfly.plugins
+ wildfly-bom-builder-plugin
+ @pom.version@
+
+
+ build-bom
+
+ build-bom
+
+
+
+
+ @pom.groupId@
+ dependency-management-pom
+ $@pom.version@
+
+
+ *
+ *
+ provided
+
+
+
+
+
+
+
diff --git a/src/it/dependency-management-pom/verify.groovy b/src/it/dependency-management-pom/verify.groovy
new file mode 100644
index 0000000..f6cae23
--- /dev/null
+++ b/src/it/dependency-management-pom/verify.groovy
@@ -0,0 +1,38 @@
+/*
+ ~ Copyright (C) 2013 Red Hat, Inc
+ ~
+ ~ Licensed 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 file = new File(basedir, "target/bom-pom.xml")
+def line
+def foundDependency1 = false
+def foundDependency2 = false
+file.withReader { reader ->
+ while ((line = reader.readLine())!=null) {
+ if (line.contains("commons-lang3")) {
+ foundDependency1 = true
+ }
+ if (line.contains("commons-text")) {
+ foundDependency2 = true
+ }
+ }
+}
+if (!foundDependency1) {
+ println("VERIFY ERROR: bom-pom.xml does not contain commons-lang3 dependency!")
+ return false
+}
+if (foundDependency2) {
+ println("VERIFY ERROR: bom-pom.xml should not contain commons-text dependency!")
+ return false
+}
diff --git a/src/it/multi-module-pom/invoker.properties b/src/it/multi-module-pom/invoker.properties
new file mode 100644
index 0000000..00b2ef3
--- /dev/null
+++ b/src/it/multi-module-pom/invoker.properties
@@ -0,0 +1 @@
+invoker.project = module1
diff --git a/src/it/multi-module-pom/module1/pom.xml b/src/it/multi-module-pom/module1/pom.xml
new file mode 100644
index 0000000..800ffc3
--- /dev/null
+++ b/src/it/multi-module-pom/module1/pom.xml
@@ -0,0 +1,72 @@
+
+
+
+
+ 4.0.0
+
+ @pom.groupId@
+ multi-module-pom
+ @pom.version@
+
+ module1
+ @pom.version@
+ jar
+
+
+ UTF-8
+
+
+
+
+
+
+ commons-io
+ commons-io
+
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+
+ org.apache.commons
+ commons-text
+
+
+
+
+
+
+ commons-io
+ commons-io
+ 2.16.1
+
+
+ org.apache.commons
+ commons-text
+ 1.12.0
+ provided
+
+
+
+
+
+
diff --git a/src/it/multi-module-pom/module2/pom.xml b/src/it/multi-module-pom/module2/pom.xml
new file mode 100644
index 0000000..0f4e9d4
--- /dev/null
+++ b/src/it/multi-module-pom/module2/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+ 4.0.0
+
+ @pom.groupId@
+ multi-module-pom
+ @pom.version@
+
+ module2
+ @pom.version@
+ jar
+
+
+ UTF-8
+
+
+
+
+ commons-cli
+ commons-cli
+
+
+
+
diff --git a/src/it/multi-module-pom/module3/pom.xml b/src/it/multi-module-pom/module3/pom.xml
new file mode 100644
index 0000000..c99b096
--- /dev/null
+++ b/src/it/multi-module-pom/module3/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+ 4.0.0
+
+ @pom.groupId@
+ multi-module-pom
+ @pom.version@
+
+ module3
+ @pom.version@
+ jar
+
+
+ UTF-8
+
+
+
+
+ commons-cli
+ commons-cli
+
+
+
+
diff --git a/src/it/multi-module-pom/pom.xml b/src/it/multi-module-pom/pom.xml
new file mode 100644
index 0000000..a45875a
--- /dev/null
+++ b/src/it/multi-module-pom/pom.xml
@@ -0,0 +1,94 @@
+
+
+
+
+ 4.0.0
+
+ @pom.groupId@
+ multi-module-pom
+ @pom.version@
+ pom
+
+
+ module1
+ module2
+ module3
+
+
+
+ UTF-8
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.14.0
+
+
+
+ commons-cli
+ commons-cli
+ 1.9.0
+
+
+
+
+
+
+
+ org.wildfly.plugins
+ wildfly-bom-builder-plugin
+ @pom.version@
+
+
+ build-bom
+
+ build-bom
+
+
+
+
+ @pom.groupId@
+ multi-module-pom
+ $@pom.version@
+
+ PROJECT_DEPENDENCIES
+
+
+ *
+ *
+ provided
+
+
+
+
+ *
+ *
+ compile
+ provided
+
+
+
+
+
+
+
+
diff --git a/src/it/multi-module-pom/verify.groovy b/src/it/multi-module-pom/verify.groovy
new file mode 100644
index 0000000..58ff766
--- /dev/null
+++ b/src/it/multi-module-pom/verify.groovy
@@ -0,0 +1,62 @@
+/*
+ ~ Copyright (C) 2013 Red Hat, Inc
+ ~
+ ~ Licensed 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 file = new File(basedir, "module1/target/bom-pom.xml")
+def line
+def foundDependency1 = false
+def foundDependency2 = false
+def foundDependency3 = false
+def foundDependency4 = false
+def providedCount = 0
+file.withReader { reader ->
+ while ((line = reader.readLine())!=null) {
+ if (line.contains("commons-lang3")) {
+ foundDependency1 = true
+ }
+ if (line.contains("commons-io")) {
+ foundDependency2 = true
+ }
+ if (line.contains("commons-cli")) {
+ foundDependency3 = true
+ }
+ if (line.contains("commons-text")) {
+ foundDependency4 = true
+ }
+ if (line.contains("provided")) {
+ providedCount = providedCount + 1
+ }
+ }
+}
+if (!foundDependency1) {
+ println("VERIFY ERROR: bom-pom.xml does not contain commons-lang3 dependency!")
+ return false
+}
+if (!foundDependency2) {
+ println("VERIFY ERROR: bom-pom.xml does not contain commons-io dependency!")
+ return false
+}
+if (foundDependency3) {
+ println("VERIFY ERROR: bom-pom.xml should not contain commons-cli dependency!")
+ return false
+}
+if (foundDependency4) {
+ println("VERIFY ERROR: bom-pom.xml should not contain commons-text dependency!")
+ return false
+}
+if (providedCount != 2) {
+ println("VERIFY ERROR: bom-pom.xml should contain 2 dependencies with provided scope!")
+ return false
+}
diff --git a/src/it/settings.xml b/src/it/settings.xml
new file mode 100644
index 0000000..57bb172
--- /dev/null
+++ b/src/it/settings.xml
@@ -0,0 +1,36 @@
+
+
+
+
+ it-repo
+
+
+ local.central
+ @localRepositoryUrl@
+
+ true
+
+
+ true
+
+
+
+
+
+ local.central
+ @localRepositoryUrl@
+
+ true
+
+
+ true
+
+
+
+
+
+
+ it-repo
+
+
+
diff --git a/src/main/java/org/wildfly/plugins/bombuilder/BuildBomMojo.java b/src/main/java/org/wildfly/plugins/bombuilder/BuildBomMojo.java
index 683553e..28994e0 100644
--- a/src/main/java/org/wildfly/plugins/bombuilder/BuildBomMojo.java
+++ b/src/main/java/org/wildfly/plugins/bombuilder/BuildBomMojo.java
@@ -213,6 +213,9 @@ public class BuildBomMojo
@Parameter
private List scopeOverrides;
+ @Parameter(defaultValue = "DEPENDENCY_MANAGEMENT")
+ private DependencySource dependencySource;
+
/**
* The current project
*/
@@ -422,8 +425,19 @@ private void finalizeModel(Model model) throws MojoExecutionException {
mavenProject.addAttachedArtifact( pomArtifact );
}
+ private List getDependencies() {
+ if (dependencySource == DependencySource.PROJECT_DEPENDENCIES) {
+ return mavenProject.getDependencies();
+ }
+ else if (mavenProject.getDependencyManagement() != null) {
+ return mavenProject.getDependencyManagement().getDependencies();
+ }
+ return null;
+ }
+
private void addDependencyManagement(Model pomModel) throws MojoExecutionException {
- if (mavenProject.getDependencyManagement() == null || mavenProject.getDependencyManagement().getDependencies() == null) {
+ final List dependencies = getDependencies();
+ if (dependencies == null) {
return;
}
pomModel.setDependencyManagement(new DependencyManagement());
@@ -456,7 +470,7 @@ private void addDependencyManagement(Model pomModel) throws MojoExecutionExcepti
VersionResolverFactory factory = new VersionResolverFactory(repositorySystem, session, mapper);
channelSession = new ChannelSession(channels, factory);
}
- for (Dependency dependency : mavenProject.getDependencyManagement().getDependencies()) {
+ for (Dependency dependency : dependencies) {
if (isExcludedDependency(dependency) && getIncludedTransitiveDependency(dependency) == null) {
getLog().info("Skipping dependency excluded by config: "+dependency.getManagementKey());
continue;
diff --git a/src/main/java/org/wildfly/plugins/bombuilder/DependencySource.java b/src/main/java/org/wildfly/plugins/bombuilder/DependencySource.java
new file mode 100644
index 0000000..82496ae
--- /dev/null
+++ b/src/main/java/org/wildfly/plugins/bombuilder/DependencySource.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2023 Red Hat, Inc. and/or its affiliates
+ * and other contributors as indicated by the @author tags.
+ *
+ * Licensed 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.
+ */
+package org.wildfly.plugins.bombuilder;
+
+public enum DependencySource
+{
+ /**
+ * Dependencies from dependency management.
+ */
+ DEPENDENCY_MANAGEMENT,
+ /**
+ * Project dependencies.
+ */
+ PROJECT_DEPENDENCIES;
+}