Composite build not working properly

I have the following build that works fine and is properly consumable and working like expected when publishing to maven local repository and consuming from maven local repository:

plugins {
    id 'java-library'
    id 'maven-publish'

group 'net.kautler.discord'
version '0.1.0'
description 'Log appender to send log messages to a Discord channel'
defaultTasks 'build'
sourceCompatibility = 1.8

repositories {

def versions = [
        collections4: '4.1',
        discord4j   : '2.10.1',
        jackson     : '2.9.3',
        javacord    : '3.0.1',
        jda         : '3.8.1_450',
        json        : '20160810',
        log4j       : '2.11.1'

def additionalSourceSets = [

dependencies {
    api "org.apache.logging.log4j:log4j-core:${versions.log4j}"

    log4jAnnotationProcessor "org.apache.logging.log4j:log4j-core:${versions.log4j}"
    log4jCompileOnly "org.apache.logging.log4j:log4j-core:${versions.log4j}"
    log4jCompileOnly sourceSets.log4jApi.output

    javacordCompileOnly "org.javacord:javacord-core:${versions.javacord}"
    javacordCompileOnly "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
    javacordCompileOnly sourceSets.log4jApi.output

    discord4jCompileOnly "com.discord4j:Discord4J:${versions.discord4j}"
    discord4jCompileOnly sourceSets.log4jApi.output

    jdaCompileOnly "net.dv8tion:JDA:${versions.jda}"
    jdaCompileOnly "org.json:json:${versions.json}"
    jdaCompileOnly "org.apache.commons:commons-collections4:${versions.collections4}"
    jdaCompileOnly sourceSets.log4jApi.output

tasks.withType(JavaCompile) {
    options.encoding 'UTF-8'
    if (JavaVersion.current().java9Compatible) {
        afterEvaluate {
            options.compilerArgs << '--release' << platform.targetCompatibility.majorVersion

jar {
    from additionalSourceSets.output

javadoc {
    classpath = files(classpath + additionalSourceSets.output + additionalSourceSets.compileClasspath)
    source additionalSourceSets.allJava

task javadocJar(type: Jar) {
    group 'build'
    description 'Assembles a jar archive containing the JavaDoc files.'
    classifier 'javadoc'
    from javadoc

task sourcesJar(type: Jar) {
    group 'build'
    description 'Assembles a jar archive containing the Java source files.'
    classifier 'sources'
    from additionalSourceSets.allJava

artifacts {
    archives javadocJar, sourcesJar

publishing {
    publications {
        discordLogger(MavenPublication) {
            artifact javadocJar
            artifact sourcesJar

Now I tried to use this build as composite build and included it via settings.gradle.
Unfortunatley even the build via commandline now fails.
It calls the :jar task and all the compile tasks of the separate source sets, but it does not use the built JAR, but the compile-output folder of the main sourceset which of course is empty as the main sourceset is only an aggregator.

Is there a way to solve this in a better or more idiomatic way that also works better with composite builds?

I tried replacing

jar {
    from additionalSourceSets.output


def compileJavaDestinationDir = compileJava.destinationDir
task compileJava(type: Copy, overwrite: true) {
    from additionalSourceSets.output
    into compileJavaDestinationDir

This feels pretty awkward, but it still publishes the correct JAR and the composite build works from commandline Gradle.
But from the IDE it still does not work as this of course wants to know the source folders to resolve and compile itself and it only gets the main sourceset source folder as dependency.
And I’d like to prevent now additionally having to configure the eclipse model and the idea model just to get the composite build working.

There must be an easier way I don’t see, or maybe I should open an improvement request for composite build. Or is my approach to separate the classes for compilation but combine them in one artifact simply not supported. :frowning: I’d like to have the classes separate, as they depend on different optional runtime dependencies to support different competing libraries and make sure I only use what is present in each.