rtk icon indicating copy to clipboard operation
rtk copied to clipboard

feat: add Maven (mvn) command support with 7 subcommands

Open alexvanacker opened this issue 8 months ago • 19 comments

Summary

Closes #338

  • Add token-optimized filtering for Maven CLI output (mvn, mvnw, ./mvnw with auto-detection)
  • 7 subcommands: compile, test, package, clean, integration-test, install, dependency:tree, plus Other passthrough
  • Auto-inject -B (batch mode) + --no-transfer-progress to 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 (./mvnw preferred over mvn)

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 --help lists 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  █░░░░░░░░░

alexvanacker avatar Mar 06 '26 10:03 alexvanacker

Good coverage with 7 subcommands + passthrough. A few things to address:

  1. Rebase on master
  2. Code duplication — 7 run_* functions are nearly identical, a shared runner would cut ~300 lines
  3. Missing tests — no token savings tests for package/install, no tests for integration-test
  4. stdout/stderr merged — filtered output goes all to stdout, breaks piped usage
  5. No snapshot tests

Note: PR #288 also covers Maven with a DRY shared runner pattern. We're evaluating both.

pszymkowiak avatar Mar 06 '26 12:03 pszymkowiak

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.

alexvanacker avatar Mar 06 '26 13:03 alexvanacker

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!

pszymkowiak avatar Mar 10 '26 15:03 pszymkowiak

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:

  1. 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.

  2. 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.

  3. 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.

  4. Warning deduplication Identical [WARNING] lines get grouped with counts: "Using deprecated API (x3)" instead of 3 repeated lines.

  5. 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.

  6. 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."

  7. 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?

alexvanacker avatar Mar 11 '26 13:03 alexvanacker

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!

pszymkowiak avatar Mar 11 '26 21:03 pszymkowiak

Sorry @pszymkowiak I missed your latest message, just changed the target branch and rebased

alexvanacker avatar Mar 16 '26 13:03 alexvanacker

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 20 '26 16:03 CLAassistant

Hi team, I am looking forward for this feature, any progress here?

msegoviadev avatar Mar 22 '26 13:03 msegoviadev

@pszymkowiak could you review this pr once again and approve? mvn and mvnw improvemtns would be great to have

dandudzi avatar Mar 22 '26 17:03 dandudzi

waiting for this feature. i did a local version for myself. if it be master release, rtk will be better.

qingmo avatar Mar 25 '26 03:03 qingmo

Rebased on develop and CLA signed!

alexvanacker avatar Mar 26 '26 10:03 alexvanacker

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

aeppling avatar Mar 26 '26 18:03 aeppling

This should be done https://github.com/aeppling

alexvanacker avatar Apr 07 '26 13:04 alexvanacker

Hi @alexvanacker, congratulations on your hard work! I'm looking forward to this feature. I hope it will be merged very soon.

marlonpatrick avatar Apr 23 '26 14:04 marlonpatrick

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

novoj avatar Apr 24 '26 07:04 novoj

Thank https://github.com/novoj! Will definitely integrate this :)

alexvanacker avatar Apr 24 '26 12:04 alexvanacker

can't wait this to be merged

ouarrtaha avatar Apr 29 '26 00:04 ouarrtaha

Hey! looks really nice for maven support, Is there any news to merge this PR?

jo-pouradier avatar May 28 '26 09:05 jo-pouradier

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-progress injection
  • 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.

KuSh avatar Jun 14 '26 22:06 KuSh