I setup a multi-project build. Let’s call my two projects “lib” and “app”. “app” requires services registered through META-INF/services generated from “lib”. It needs to be able to find the JAR generated from “lib” to build up a custom classpath.
Here’s an excerpt of the build.gradle.kts file of “app”.
dependencies {
compile(project(":lib"))
}
tasks.create<MyTask>("doSomething") {
addCompileClasspath = true
}.dependsOn(":lib:assemble")
tasks["build"].finalizedBy(tasks["doSomething"])
In a Gradle plugin I’m also writing, I need to get the Java compile classpath. I get it from within my plugin like this (Java code):
project.getConfigurations().getByName("compileClasspath")
When I dump this out as a classpath, it points to only the compiled classes and not the generated JAR:
/Users/blah/lib/build/classes/java/main
This directory does not contain resources or the relevant META-INF/services file, so my services aren’t found when executing “app”.
Why am I getting the compiled classes and not the JAR?
More details if needed:
My settings.gradle.kts looks like this:
rootProject.name = "foo"
include(":lib")
include(":app")
Then root build.gradle.kts is pretty minimal. Looks like this:
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
Note that “lib” applies the java-library
plugin while app
does not.