Project dependencies to custom source sets

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.

The point is, you are not using the jar for the consumer compilation.
One of the benefits of the java-library plugins is, that it registers secondary variants with which consumers in the same build can directly use the compiled classes without needing to process resources and build a jar needlessly just to compile.

With your exotic configuration this fails of course, as you stuff additional things into the jar that are not supposed to be there.

Maybe it works if you explicitly request the main variant instead of the secondary one for that dependency, no idea. Never tried such a hacky setup.