Add dependency:add, dependency:remove and dependency:search goals using DomTrip#1600
Add dependency:add, dependency:remove and dependency:search goals using DomTrip#1600gnodet wants to merge 6 commits intoapache:masterfrom
Conversation
Thin mojos using DomTrip for lossless POM editing (add/remove) and Sonatype Central Search API with jakarta.json for artifact search. - dependency:add supports -Dgav, -Dmanaged, -Dscope, -DuseProperty, -DpropertyName - dependency:remove supports -Dgav, -Dmanaged - dependency:search supports -Dquery, -Drows, works without a project Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dependency:add now auto-detects the project's dependency management conventions by analyzing existing dependencies: - Detects if managed dependencies are used (version-less deps) - Detects if version properties are used and the naming pattern - Walks the parent chain to find the right POM for managed deps - Adds versioned entry to parent and version-less entry to current POM Explicit flags (-Dmanaged, -DuseProperty, -DpropertyName) override. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9 ITs covering: - add-dependency: basic add to existing POM - add-dependency-managed: add to dependencyManagement - add-dependency-scope: add with scope - add-dependency-property: add with version property - add-dependency-align: auto-detect managed deps + property convention - remove-dependency: remove from dependencies - remove-dependency-managed: remove from dependencyManagement - remove-dependency-not-found: expected failure when dep doesn't exist - search-dependency: search Maven Central (requires network) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use groovy.xml.XmlSlurper (required in Groovy 4+) - Add domtrip-core as explicit dependency (used transitively via domtrip-maven) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove align=false from basic add-dependency and add-dependency-scope ITs so they exercise the default align=true code path - Add add-dependency-align-properties IT: tests auto-detection of property naming convention (.version suffix) without managed deps Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@gnodet is |
- Scan parent POM for property patterns when child has version-less deps
- Fix double-scan bug in analyzePropertyPatterns
- Recognize -version suffix convention (e.g. Camel's ${jackson-version})
- Add multi-module ITs for both .version and -version conventions
- Add site documentation for add, remove and search goals
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Not yet used by other plugins at the moment afaik. It will probably come over time. There was some discussion for the release-plugin which was stalled because DomTrip was really new at that time. All the plugins that modify POMs are usually a pain because they can loose lots of stuff from the POMs and cause big diffs in the resulting XML, even though both are semantically equivalent (spaces in attributes, quotes, comments before the document element, etc...). Domtrip is really 100% roundtrip safe. Adding new dependencies is not really a problem per se, we just need to do that wisely. In that very case, I'd rather add dependencies to domtrip + a json parser rather than recoding those. |
|
@gnodet and what is the license compatibility for using DomTrip in an Apache Licensed maven plugin? |
Summary
Alternative approach to #1599 — thin mojos leveraging DomTrip for lossless POM editing and
jakarta.jsonfor search API parsing.dependency:add— adds/updates a dependency, preserving formatting, comments, and whitespace. Supports-Dgav,-Dmanaged,-Dscope,-DuseProperty,-DpropertyName,-Dalign.dependency:remove— removes a dependency (regular or managed).dependency:search— searches Maven Central via the Sonatype Central Search API. Non-interactive tabular output.Convention auto-detection (
align=true, the default)When adding a dependency, the mojo analyzes existing dependencies to automatically follow the project's patterns:
<dependencyManagement>), the new dep is added the same way${...}), a property is created following the detected naming convention.version(e.g.guava.version),-version(e.g.guava-version, Camel-style),Version(camelCase), andversion.prefix conventions<dependencyManagement>, adds the managed dep + property there, and adds a version-less dep to the child POMExplicit flags (
-Dmanaged,-DuseProperty,-DpropertyName,-Dalign=false) override auto-detected conventions.Usage examples
Dependencies added
eu.maveniverse.maven.domtrip:domtrip-maven:0.6.0(EPL-2.0, ASF Cat-B — already accepted in Maven 4 core)org.glassfish:jakarta.json:2.0.1promoted from test to compile scope (already in the project)Test plan
.versionconvention-versionconvention (Camel-style)🤖 Generated with Claude Code
Claude Code on behalf of Guillaume Nodet