johnpoth/jshell-maven-plugin

Only the project files end up on the classpath, not dependencies

briangoetz opened this issue · 5 comments

I have a multi-module project with various maven dependencies. When I run:

mvn com.github.johnpoth:jshell-maven-plugin:1.3:run -Djshell.options="--enable-preview"

it only puts the project files on the classpath; not the maven dependencies. If I ask System.getProperties() for the class path, I get:

java.class.path=:/home/brian/work/jdk/bytecode-api/library/target/classes

But if I do mvn dependency:build-classpath, I get:

/home/brian/.m2/repository/org/testng/testng/7.1.0/testng-7.1.0.jar:/home/brian/.m2/repository/com/beust/jcommander/1.72/jcommander-1.72.jar:/home/brian/.m2/repository/com/google/inject/guice/4.1.0/guice-4.1.0-no_aop.jar:/home/brian/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/home/brian/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar:/home/brian/.m2/repository/com/google/guava/guava/19.0/guava-19.0.jar:/home/brian/.m2/repository/org/yaml/snakeyaml/1.21/snakeyaml-1.21.jar:/home/brian/.m2/repository/org/ow2/asm/asm/9.0/asm-9.0.jar:/home/brian/.m2/repository/org/ow2/asm/asm-tree/9.0/asm-tree-9.0.jar:/home/brian/.m2/repository/org/glassfish/javax.json/1.1/javax.json-1.1.jar

I would have expected to see the latter as my classpath inside jshell?

Hello @briangoetz

The jshell-maven-plugin plugin will put all your runtime scoped dependencies on the class path.

If you want to use your test scope dependencies you should add -DtestClasspath. Based on the output you gave, I think this is what's missing as testng, and it's transitive dependencies, are probably test scoped in your pom. Maybe I should use this by default.

If you want to see which dependencies are added to JShell you can run Maven in debug mode -X and you should see them logged just before JShell is launched. System.getProperties()'s output in JShell will be truncated to 1000 characters (on my default truncation settings).

If none of the above works I'd be happy to look into it.

PS: Big fan of your book Java Concurrency in Practice and your work to make Java and it's ecosystem so pleasant to use

Yes, that seems to be what is going on. What threw me is that when I ask mvn dependency:build-classpath, it gives me everything, and I assumed the plugin would do the same. Adding -DtestClasspath did the trick, but I agree, this should probably be the default.

I did find a separate bug; I have a multi-module project, and when I run mvn com.github.johnpoth:jshell-maven-plugin:1.3:run -Djshell.options="--enable-preview" -DtestClasspath at the top level project (which has four modules), it runs jshell four times....

Glad that worked! Will add the test class path by default in the next version. I'll also throw an error if the plugin is run on a top level project which shouldn't be too hard to detect

Concur that it would be nice if -DtestClasspath was the default, since this also includes provided dependencies, which I often use for utility libraries.

Fixed with 1c90e8d