8000 maven: wire the local repository to a session state dir (MAVEN_REPO_LOCAL) by bryan-minimal · Pull Request #902 · gominimal/pkgs · GitHub
[go: up one dir, main page]

Skip to content

maven: wire the local repository to a session state dir (MAVEN_REPO_LOCAL) - #902

Merged
bryan-minimal merged 4 commits into
mainfrom
maven-repo-state-dir
Oct 22, 2026
Merged

bryan-minimal merged 4 commits into
mainfrom
maven-repo-state-dir

Conversation

@bryan-minimal
@bryan-minimal bryan-minimal commented Oct 16, 2026 •
Copy link
Copy Markdown
Member

Why

gradle declares its cache as a session state directory (env_state_wiring: GRADLE_USER_HOME). maven declared nothing. So the maven stack, and the java loadout in #899, hardcode MAVEN_OPTS=-Dmaven.repo.local=/state/m2/repository, and a session that uses maven outside those stacks falls back to ~/.m2.

What

  • attrs.env_state_wiring = { env_var = "MAVEN_REPO_LOCAL", prefix = "maven" }, the same mechanism gradle, go, node-lts, bun and deno use.
  • Maven has no environment variable for its local repository, so the /usr/bin/mvn wrapper passes -Dmaven.repo.local="$MAVEN_REPO_LOCAL" when the variable is set. A -Dmaven.repo.local the caller passes comes later on the command line and still wins. When set, it also overrides a <localRepository> in the user's settings.xml (a -D property beats settings), which is intended.
  • The maven stack drops its MAVEN_OPTS=-Dmaven.repo.local=/state/m2/repository. The wired variable reaches stack builds too, and the wrapper's -D beats MAVEN_OPTS, so keeping both would have silently moved stack builds to a new, empty repository. The gradle stack likewise relies on its wiring alone.
  • needs = { dns, internet }, the consumer-facing network dep (maven's own build stays offline). This is the one convention for the JVM build tools: jbang (jbang: add 0.142.0 #903) already declares it, and mvnd (mvnd: add 1.0.6 (Maven Daemon, embeds Maven 3.9.16) #904) does too.

Test

repo_local_from_state_dir: a minimal packaging=pom project; validate binds no plugins, so it runs offline (-o). With MAVEN_REPO_LOCAL=/tmp/m2-state-repo, it asserts BUILD SUCCESS and that Maven's -X output names that path, and it prints the mvn output when it fails. Verified in a pkgbuild session (min package build --rebuild maven + min check --packages maven): every check passes, including standalone tests. The package evaluates with mip dump.

Follow-up

The java loadout in #899 (draft) still sets the same MAVEN_OPTS; it should drop it once this lands. gradle doesn't declare needs yet; it should get the same block in its own PR.

🤖 Generated with Claude Code

…OCAL)

gradle declares its cache via env_state_wiring (GRADLE_USER_HOME);
maven declared nothing, so the maven/java stacks papered over it with
MAVEN_OPTS=-Dmaven.repo.local=/state/m2/repository and plain sessions
used ~/.m2. Declare env_state_wiring { MAVEN_REPO_LOCAL, prefix maven }
and have /usr/bin/mvn pass it as -Dmaven.repo.local (Maven has no env
var for it); a caller's own -Dmaven.repo.local still wins.

Test: an offline packaging=pom `validate` with MAVEN_REPO_LOCAL set
succeeds and Maven's debug output names the wired path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner October 16, 2026 20:28
@bryan-minimal
Copy link
Copy Markdown
Member Author

/build

@coderabbitai
coderabbitai Bot commented Oct 16, 2026 •
Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 3 billable files and costs up to $0.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 13 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 58 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: gominimal/pkgs/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 52afedcd-1489-4fb4-9011-6424bf1a985d
📥 Commits

Reviewing files that changed from the base of the PR and between 0618acc and c678fa9.

📒 Files selected for processing: 3
  • packages/maven/build.ncl
  • packages/maven/build.sh
  • stacks/maven/stack.ncl
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wiring is right and matches gradle's env_state_wiring shape. A -Dmaven.repo.local in the wrapper is the correct approach, since Maven has no environment variable for it, and a later caller -D still wins.

  1. It changes behaviour for the maven stack. stacks/maven/stack.ncl sets MAVEN_OPTS=-Dmaven.repo.local=/state/m2/repository. With this PR, the wired variable is also set in stack builds, and the command-line -D beats MAVEN_OPTS, so stack builds move to a new, empty repository. "Unset means unchanged" doesn't hold there. Please drop the stack's MAVEN_OPTS in this PR so there's one location.
  2. The wired path also silently overrides a user's settings.xml <localRepository>. That's probably intended, but worth a line in the comment.
  3. mvnd (#904) ignores this variable, so the two will diverge unless #904's wrapper forwards it (commented there).
  4. Rebase needed: the branch predates #897 (jdk → Temurin 25).
  5. Nit: the test at build.ncl:81 captures output with out=$(...) under set -e, so a failed mvn exits silently. Echo $out on failure.

Generated by Claude Code

bryan-minimal and others added 3 commits October 21, 2026 19:04
Review fixes: drop the maven stack's MAVEN_OPTS=-Dmaven.repo.local (the
wired MAVEN_REPO_LOCAL already reaches stack builds and its -D beat
MAVEN_OPTS, so stack builds were silently moving to the state dir anyway;
the gradle stack likewise relies on its wiring alone). Note that the
wired path overrides settings.xml <localRepository>. The
repo_local_from_state_dir test now echoes mvn's output when it fails
instead of exiting silently under set -e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JVM build tools get one convention: needs { dns, internet } as the
consumer-facing network dep (resolving from Maven Central is the tool's
job), the same as jbang, curl, go and uv. maven's own build stays offline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
Copy link
Copy Markdown
Member Author

Thanks @norrietaylor. Addressed in 4d3f496 and c678fa9, on top of a merge of main (c4e8c15):

  1. Stack behaviour: you're right that "unset means unchanged" didn't hold for the stack. stacks/maven/stack.ncl no longer sets MAVEN_OPTS, so the wired /state/maven is the only location, the same way the gradle stack relies on its wiring alone. Nothing else in pkgs references /state/m2/repository. The draft java loadout in stacks: java development loadout (jdk + maven + gradle + jdtls) #899 sets the same MAVEN_OPTS, and I've noted in the body that it should drop it too.
  2. settings.xml: the wrapper comment now says the wired path overrides a <localRepository> there, and that this is intended.
  3. mvnd: mvnd: add 1.0.6 (Maven Daemon, embeds Maven 3.9.16) #904's wrapper now forwards MAVEN_REPO_LOCAL, so the two share one repository. mvnd: add 1.0.6 (Maven Daemon, embeds Maven 3.9.16) #904's body says to merge it after this PR.
  4. jdk: current LTS (meta over jdk-25); add jdk-25 (Temurin 25) and jdk-21 (Temurin 21) #897: merged main, so CI now builds and tests on Temurin 25. Our branch rebuilds on its own.
  5. Test: the test now has an ERR trap that prints $out when mvn or a grep fails.

Also, for the needs question you raised on #904: maven now declares needs = { dns, internet } as the consumer-facing network dep, the same as jbang and (with #904) mvnd. gradle should get the same block in its own PR.

Verified in a pkgbuild session (min package build --rebuild maven, then min check --packages maven): every check passes, including standalone tests. nickel format --check and mip dump are clean.

🤖 Generated with Claude Code

@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four points from my last review are addressed and verified in code:

  • the stack's MAVEN_OPTS is dropped;
  • the settings.xml override is documented;
  • the branch is past #897;
  • the ERR trap prints $out on failure.

needs now matches jbang and the others.

Non-blocking:

  • The comment at build.sh:47-55 could also mention that the wired -D beats a user's MAVEN_OPTS and .mvn/maven.config.
  • Existing maven-stack users lose their /state/m2/repository cache once; worth a line in the merge notes.
  • The test's fixed /tmp/m2-state-repo (build.ncl:92) could use $PWD, as mvnd's tests do.

Please merge this before #904.


Generated by Claude Code

@bryan-minimal
bryan-minimal added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 3ef1122 Oct 22, 2026
11 checks passed
@bryan-minimal
bryan-minimal deleted the maven-repo-state-dir branch October 22, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0