Skip to content

feat: convention-aligned dependency addition in PomEditor #170

@gnodet

Description

@gnodet

Summary

Add convention auto-detection to PomEditor.Dependencies so that when adding a dependency, the edit follows the project's existing dependency management style.

Claude Code on behalf of Guillaume Nodet

Motivation

Multiple tools need this capability:

Currently each consumer must implement its own convention detection. This logic belongs in domtrip-maven's PomEditor since it's a POM editing concern.

Proposed API

// High-level: detect conventions and add accordingly
editor.dependencies().addAligned(Coordinates coords);

// Or with explicit control:
editor.dependencies().addAligned(Coordinates coords, AlignOptions options);

Convention Detection

When adding a dependency, analyze existing <dependencies> and <properties> to detect:

1. Managed dependency style

  • If most existing <dependency> entries are version-less (version delegated to <dependencyManagement>), the new dependency should be added the same way:
    • Add versioned entry to <dependencyManagement>
    • Add version-less <dependency>
  • If most entries have inline versions, add with inline version

2. Version property style

  • If most existing versions use ${...} property references, automatically create a version property
  • If most use literal versions, use literal

3. Property naming convention

Detect the dominant pattern from existing properties:

  • Dot suffix: guava.version${guava.version}
  • Dash suffix: guava-version${guava-version}
  • CamelCase: guavaVersion${guavaVersion}
  • Dot prefix: version.guava${version.guava}

Apply the same pattern when creating new version properties.

Implementation Notes

  • The PomEditor.Properties API already exists (updateProperty(), deleteProperty()) but is underutilized
  • PomEditor.Dependencies already has updateDependency() and updateManagedDependency() — the aligned version composes these
  • Explicit flags should always override detected conventions (e.g., force managed, force property, explicit property name)
  • Detection should be based on majority vote — if 7/10 deps use properties, follow that pattern

Acceptance Criteria

  • Detect managed vs inline version style
  • Detect property vs literal version style
  • Detect property naming convention
  • addAligned() method that applies detected conventions
  • Explicit overrides for all detected conventions
  • Unit tests covering each convention pattern and mixed scenarios

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