Skip to content

Expose findManagedVersion as public API #215

@gnodet

Description

@gnodet

Summary

Make PomEditor.Dependencies.findManagedVersion(Coordinates) public so callers can check whether a dependency is already locally managed before performing mutations.

Use case

When adding a transitive dependency with addAligned using VersionStyle.MANAGED, the method always creates a local <dependencyManagement> entry — even when the dependency is already managed by a parent POM. This causes unwanted local managed entries that shadow the parent's management.

Callers need to check whether a managed entry already exists locally before calling addAligned, so they can skip or clean up the redundant local entry. Currently the only way is manual DOM navigation:

boolean hadManagedEntry = editor.document().root()
        .childElement("dependencyManagement")
        .flatMap(dm -> dm.childElement("dependencies"))
        .flatMap(deps -> deps.childElements("dependency")
                .filter(coords.predicateGATC())
                .findFirst())
        .isPresent();

Proposed API

Make the existing private method public:

public String findManagedVersion(Coordinates coords)

Returns the managed version string if found locally, or null if not.

Alternatively, a boolean hasManagedDependency(Coordinates) convenience method would also work.

Claude Code on behalf of Guillaume Nodet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions