Skip to content

[#1637] Fix dependency:add routing versioned deps into dependencyManagement#1638

Merged
slawekjaranowski merged 1 commit into
apache:masterfrom
brunoborges:fix/add-managed-bom-import-1637
Jun 11, 2026
Merged

[#1637] Fix dependency:add routing versioned deps into dependencyManagement#1638
slawekjaranowski merged 1 commit into
apache:masterfrom
brunoborges:fix/add-managed-bom-import-1637

Conversation

@brunoborges

Copy link
Copy Markdown
Contributor

Fixes #1637

Problem

dependency:add with an explicit version added the dependency to the current POM's <dependencyManagement> instead of <dependencies> when the project's existing dependencies are version-less because their versions come from a BOM import — the layout produced by maven-archetype-quickstart.

mvn dependency:add -Dgav=org.apache.commons:commons-lang3:3.20.0

With align=true (default), detectConventions() set useManaged=true purely because most <dependencies> were version-less. As there was no parent POM to host the managed entry (findManagedDepsPom() returned null), the dependency was written into the current POM's <dependencyManagement> — so it was never actually added as a usable dependency. This also contradicts the align Javadoc, which says the convention is to "add managed dependency to parent POM".

Fix

The auto-detected useManaged convention now only applies when a separate parent POM actually exists to host the managed dependency. For a single/leaf POM, a versioned add goes to <dependencies>. Explicit -Dmanaged=true is unchanged and still targets <dependencyManagement>.

Testing

  • New integration test src/it/projects/add-dependency/bom-import reproduces the quickstart/BOM-import scenario and asserts the dependency lands in <dependencies> and not in <dependencyManagement>.
  • Existing AddDependencyMojoTest and spotless:check pass.
  • Manually verified against the reported scenario: commons-lang3:3.20.0 is now correctly added to <dependencies>.

…cyManagement

The `dependency:add` goal incorrectly added a versioned dependency to the
current POM's <dependencyManagement> instead of <dependencies> when the
project's existing dependencies are version-less because their versions come
from a BOM import (the standard maven-archetype-quickstart layout).

With align=true (default), detectConventions() set useManaged=true purely
because most <dependencies> were version-less, even though no parent POM
existed to host the managed entry. The result was written to the current
POM's <dependencyManagement>, which contradicts the documented behavior of
the `align` parameter ("add managed dependency to parent POM") and means the
dependency was never actually added to the project.

The auto-detected useManaged convention now only applies when a separate
parent POM exists to host the managed dependency. For a single/leaf POM a
versioned add goes to <dependencies>. Explicit -Dmanaged=true is unchanged.

Adds an integration test (add-dependency/bom-import) reproducing the case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brunoborges

Copy link
Copy Markdown
Contributor Author

Hey folks, can I get a review on this fix?

@cstamas @slawekjaranowski @slachiewicz

Comment on lines +32 to +38
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope we can use for such example any no existing artifacts, (like org.example:bom) as ddd mojo not require dependencies resolving, or we can add next mock artifact like a1 is.

When we merge it dependabot will try to updates it, and we will have next maintenance works on list

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slawekjaranowski can we merge this one as is, and I will submit another PR changing all artifacts to non-existent examples.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, waiting for next PR 😄

@slawekjaranowski slawekjaranowski merged commit fdd2b51 into apache:master Jun 11, 2026
17 checks passed
@github-actions github-actions Bot added this to the 3.11.1 milestone Jun 11, 2026
@github-actions

Copy link
Copy Markdown

@slawekjaranowski Please assign appropriate label to PR according to the type of change.

@slawekjaranowski slawekjaranowski added the bug Something isn't working label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dependency:add puts versioned dependency in <dependencyManagement> instead of <dependencies> for quickstart/BOM-import POMs

2 participants