Java-library sharing via jar when runtimeClasspath output to file

Trying to take advantage of java-library plugin in its ability to share across subprojects via class directories, not using jars…

So I have something like:


b-proj > build.gradle has a dependency to a-proj defined

dependencies {
  implementation project(':a-proj')

When I run :b-proj:classes I see only a-proj:classes running, not a-proj:jar, so that looks good.

But I need to get the runtime classpath of b-proj written to a file so when I startup Jetty I can pass that in as the classpath. So I add a custom task to b-proj that writes sourceSets.main.runtimeClasspath.asPath to a file.
When I do that it causes :b-proj:jar to run.

Any idea how I can get the classpath to a file without Gradle thinking I need the jar built?

PS: The runtime classpath output in the file refers to a-proj by its classes directory :+1:t2:, not the jar. All the more reason the jar isn’t needed.


Can you provide an MCVE?
I suspect you have something else triggering this.
I just added a tasks.register("foo") { doLast { println(sourceSets.main.get().runtimeClasspath.asPath) } } to a java-library project and executed it and the jar of that project was neither part of the output not was the task executed.