I have a multi-project setup which utilises a custom configuration and a custom source set to compile source code from the main
and my custom externals
source set into a single jar.
Excerpt from my buildSrc defining all the required configurations and source sets
val sources: Configuration = project.configurations.create("sources") {
setTransitive(false)
}
val externals = java.sourceSets.create("externals")
val dependencySourcesDir = layout.buildDirectory.dir("${extension.externalSourcesPath.get()}/sources")
val dependencyResourcesDir= layout.buildDirectory.dir("${extension.externalSourcesPath.get()}/resources")
java {
sourceSets {
named(externals.getName()) {
java.srcDir(layout.buildDirectory.dir("${extension.externalSourcesPath.get()}/sources"))
resources.srcDir(layout.buildDirectory.dir("${extension.externalSourcesPath.get()}/resources"))
}
}
tasks.jar {
from(externals.output)
}
}
For my sub-project core-basic-ecrs this now works as expected. The produced jar contains the compiled sources from both source sets.
plugins {
`java-library`
id("sdfBuild")
}
dependencies {
sourceSets.named("externals") {
sources(libs.core.basic)
}
}
Now the trouble starts, if I want to use this output as a dependency in yet another sub-project I get compilation errors.
plugins {
`java-library` // Apply the library plugin to add support for building a java library
id("sdfBuild") // This is a pre-compiled script plugin -> plugin implicitely created by gradle
}
dependencies {
sourceSets.named("externals") {
externalsImplementation(project(":core-basic-ecrs"))
sources(libs.core.objects)
}
implementation(project(":core-basic-ecrs"))
}
All classes which are part of the core-basic-ecrs externals
source set can not be found and therefore compilation fails. Do I somehow have to specifically defined a dependeny to that source set? I thought given that all source sets are part of the produced core-basic-ecrs.jar everything should be fine.