feat: resolve classpath from pom.xml and build.gradle via //DEPS - #2597
feat: resolve classpath from pom.xml and build.gradle via //DEPS#2597maxandersen wants to merge 1 commit into
Conversation
…/DEPS Treat Maven and Gradle build files as dependency references. When passed via --deps or //DEPS, JBang shells out to the build tool, caches the resolved classpath, and adds entries to the project classpath. Supports explicit paths (--deps pom.xml) and upward search from the script location (--deps ^pom.xml). This is an experimental feature.
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks @maxandersen!
|
|
@maxandersen any objections to merging this so it gets pulled into the next release? |
|
Yeah it's a biy too simplistic yet. Ie. ^ shouldn't be needed - and only be there if want to search "upward". And also need to review the lookup of the right build command and handle failure. Have you used it and four it useful? |
|
Yeah I have one big (maven / pom.xml) project with some jbang scripts embedded. I've been using it daily since I picked up this PR a month and a half ago. I'm not doing anything complicated, just picking deps from the parent pom.xml and some classes from the project as well, but no issues so far. I feel it's a nice improvement, though I'm sure others will find other use cases after you merge it and it becomes generally available. I want to say I'm pretty impressed by jbang so far. It just works, it's fast, it gets out of the way. It is a very refreshing experience, so thanks for that! |
|
Superseded by #2657, which extends this to sbt and Mill, refactors the four strategies behind a |
Experimental: build-file classpath resolution
This is an experiment — I'd like feedback on whether this is useful and worth keeping.
What it does
You can now pass a Maven or Gradle build file as a dependency. JBang shells out to the build tool, grabs the runtime classpath, caches it, and adds the entries to your script's classpath.
In source:
From the command line:
The
^prefix means "walk upward from the script location and use the nearest matching file." So^pom.xmlinsidesrc/main/java/app.javafinds thepom.xmlthree directories up.How it works
mvn dependency:build-classpath(prefersmvnwwhen present)sourceSets.main.runtimeClasspath(prefersgradlew)--freshforces re-resolution//DEPSnaturally — they're not GAVs and not source files, so they get their own handling in the existing source-dependency loopQuestions I'd like input on
Is this useful? The idea is that if you're writing a quick script inside an existing Maven/Gradle project, you get all the project's dependencies without listing them again.
Should the
^(upward search) syntax be a general thing? Right now^pom.xmland^build.gradleare the only supported forms. But should^my-utils.javaalso work — finding the nearest matching source file by walking up? That could be handy for shared utility files in monorepos, but it's also a different feature and might deserve its own discussion.Build tool execution runs arbitrary code. Maven plugins and Gradle build scripts can do anything. This is opt-in (you explicitly write
//DEPS pom.xml), but worth calling out. Should there be a trust prompt?Changes
BuildSystemClassPaths.java— new helper that detects build files, shells out, caches resultsProjectBuilder.java— intercepts build-file refs in the source-dependency loop and in CLI--depsTestBuildSystemClassPaths.java— tests with fakemvnwscriptsrunning.adoc— documents the feature as experimental