feat: add Maven (mvn) command support with 7 subcommands
Summary
Closes #338
- Add token-optimized filtering for Maven CLI output (
mvn,mvnw,./mvnwwith auto-detection) - 7 subcommands:
compile,test,package,clean,integration-test,install,dependency:tree, plusOtherpassthrough - Auto-inject
-B(batch mode) +--no-transfer-progressto eliminate interactive prompts and download noise - Surefire/Failsafe test summary parsing (last-match for aggregate results)
- Warning deduplication with counts
- Dependency tree coordinate compaction (strip
:jar:packaging and scope) - Maven wrapper auto-detection (
./mvnwpreferred overmvn)
Files changed
| File | Action | Description |
|---|---|---|
src/mvn_cmd.rs |
New | Filter module: 7 filter functions, 7 run functions, shared helpers, 22 tests |
src/main.rs |
Modified | mod mvn_cmd, MvnCommands sub-enum, routing, is_operational_command whitelist |
src/discover/rules.rs |
Modified | Rewrite pattern + rule for mvn/mvnw/./mvnw |
Token savings
| Subcommand | Savings | Rationale |
|---|---|---|
| compile | ~85% | Strip separators, plugin lines, keep errors + warnings |
| test | ~90% | Failures only (like cargo test) |
| package | ~80% | Combined compile + test + artifact summary |
| clean | ~90% | Single confirmation line |
| dependency:tree | ~60% | Strip noise, compact coordinates |
| install | ~80% | Same as package + install path |
Test plan
- [x]
cargo fmt --all --check— clean - [x]
cargo clippy --all-targets— 0 new warnings - [x]
cargo test --all— 631 passed, 0 failed - [x] Token savings verified ≥60% for all filters
- [x] Rewrite rules verified:
mvn test→rtk mvn test,./mvnw test→rtk mvn test - [x] CLI parsing verified:
rtk mvn --helplists all 7 subcommands - [X] Manual test on a Java project with Maven
🤖 Generated with Claude Code
Example on a Java project with mvn compile:
5. rtk mvn compile 1 6.2K 97.2% 26.7s █░░░░░░░░░
Good coverage with 7 subcommands + passthrough. A few things to address:
- Rebase on master
- Code duplication — 7
run_*functions are nearly identical, a shared runner would cut ~300 lines - Missing tests — no token savings tests for
package/install, no tests forintegration-test - stdout/stderr merged — filtered output goes all to stdout, breaks piped usage
- No snapshot tests
Note: PR #288 also covers Maven with a DRY shared runner pattern. We're evaluating both.
I hadn't seen https://github.com/rtk-ai/rtk/pull/288; if it covers both mvn and gradle, it would be better IMO. I'll keep this open if there are ideas you'd wish to keep from it though.
Hey @alexvanacker, heads up: RTK now ships a built-in TOML filter for mvn build output (see src/filters/mvn-build.toml, landed in PRs #349, #351, #386). Estimated savings: 80-90% — strips Downloading/Downloaded artifact noise, progress bars, and blank lines.
If your PR adds value beyond that (test result parsing, dependency analysis, multi-module aggregation, etc.), we'd love to review the delta. Otherwise, the TOML filter might be sufficient for most users.
Could you check what your module does that the TOML doesn't? Thanks!
Hey @pszymkowiak, here is a detailled diff between the PRs you quoted and this one:
The TOML filter (mvn-build.toml from #349/#351) does line-level stripping: remove Downloading/Downloaded, progress bars, [INFO] --- separators, and blank lines. That's solid for basic noise reduction on compile/package/clean/install.
Our Rust module (mvn_cmd.rs) adds semantic parsing that TOML can't express — here's what's different:
-
Test result aggregation (Surefire/Failsafe) Maven emits per-class Tests run: lines AND per-module aggregate lines. We distinguish between them (aggregate lines lack Time elapsed:), prefer aggregates, and fall back to accumulating per-class results in multi-module reactors. A TOML keep_lines_matching would show all Tests run: lines raw — no aggregation.
-
Test failure extraction We parse <<< FAILURE! / <<< ERROR! blocks, extract the test name (testAdd(com.example.AppTest)), capture assertion messages, and filter out framework stack traces (org.junit., org.mockito., sun.*). Output is structured: up to 10 failures with 5 lines each. TOML has no state machine for this.
-
Dependency tree compaction mvn dependency:tree outputs 5-6 part Maven coordinates like org.springframework:spring-web:jar:6.1.1:compile. We parse and compact to org.springframework:spring-web:6.1.1, handling 4/5/6-part formats (including classifiers). TOML replace can't do conditional field extraction based on colon-count.
-
Warning deduplication Identical [WARNING] lines get grouped with counts: "Using deprecated API (x3)" instead of 3 repeated lines.
-
Artifact tracking mvn package/install output extracts the JAR/WAR filename from Building jar: /long/path/myapp-1.0.jar → shows just myapp-1.0.jar in the summary line.
-
Failsafe integration-test warning mvn integration-test can show BUILD SUCCESS even when ITs fail (Failsafe defers to verify phase). We detect this and append a note: "Use rtk mvn verify for accurate results."
-
Per-subcommand output format Each of the 7 goals (compile/test/package/clean/install/integration-test/dependency:tree) gets a tailored one-line summary with contextual info (source count for compile, test counts for test, artifact name for package, entry count for dependency:tree).
Token savings comparison:
- TOML filter: ~70-80% (strip noise lines)
- Rust module: ~75-95% depending on subcommand (semantic extraction → single summary line)
So the PRs are complementary: the TOML handles the generic mvn case, our module handles the 7 most common goals with deeper parsing.
Happy to adjust the PR to disable the TOML filter for goals we handle (to avoid double-filtering), or to keep both with our module taking priority, what do you think?
Hi! Thanks for the contribution! Since March 6, all PRs should target the develop branch instead of master (see CONTRIBUTING.md).
Could you update the base branch? Click Edit at the top right of this PR and change it from master to develop.
Thanks!
Sorry @pszymkowiak I missed your latest message, just changed the target branch and rebased
Hi team, I am looking forward for this feature, any progress here?
@pszymkowiak could you review this pr once again and approve? mvn and mvnw improvemtns would be great to have
waiting for this feature. i did a local version for myself. if it be master release, rtk will be better.
Rebased on develop and CLA signed!
Hey
We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.
No logic changes — only file moves and import path updates.
What you need to do
Rebase your branch on develop when receiving this comment:
git fetch origin && git rebase origin/develop
Git detects renames automatically. If you get import conflicts, update the paths:
use crate::git; // now: use crate::cmds::git::git;
use crate::tracking; // now: use crate::core::tracking;
use crate::config; // now: use crate::core::config;
use crate::init; // now: use crate::hooks::init;
use crate::gain; // now: use crate::analytics::gain;
Need help rebasing? Tag @aeppling
This should be done https://github.com/aeppling
Hi @alexvanacker, congratulations on your hard work! I'm looking forward to this feature. I hope it will be merged very soon.
I couldn't wait for this to be merged, so I created my own fork where I experiment with this feature. I found out, that agents often mix the argument positions, which works ok with Maven, but confuse the RTK which then doesn't use the mvn filtering, also not all calls are intercepted - commit which fixes it is here: https://github.com/novoj/rtk/commit/34a8452c52ad2ffbc68bff8330fa02b42de72581 (I don't know if you'd want to integrate it).
Another added thing is support for test-compile goal - which is symmetrical wit standard compile: https://github.com/novoj/rtk/commit/97fc554a05f40b85cf38f914272e4c4a02bbf2c3
Thank https://github.com/novoj! Will definitely integrate this :)
can't wait this to be merged
Hey! looks really nice for maven support, Is there any news to merge this PR?
Hi @alexvanacker, thanks for your PR. mvn support has been integrated through #1956
But some of your work could still make it in. Most notably:
- dedicated clean and dependency:tree filters.
- mvnd support
-B(batch mode) +--no-transfer-progressinjection- better artifact tracking in package/install output
- failsafe integration-test warning when integration-test shows BUILD SUCCESS
But this will require handling conflicts and integrating with current code. Hope you'll find some time and interest.