Include other gradle project in Jar

Greetings,

I have two sub projects, Core & Game, and I am trying to make it so project Game will build with project Core inside and all dependencies that are to be build inside of Cores jar, but NOT dependencies that are not supposed to be built into Cores jar.

My Core build.gradle is:

configurations {
    includeInJar
}

dependencies {
    
    compile fileTree(include: ['*.jar'], dir: '../Libraries')

    // https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2
    includeInJar group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1'

    configurations.compile.extendsFrom(configurations.includeInJar)
}

jar {
    from configurations.includeInJar.collect { zipTree it }
}

And my Game build.gradle is

configurations {
    includeInJar
}

dependencies {
    includeInJar project(':Core')
    configurations.compile.extendsFrom(configurations.includeInJar)
}

jar {
    from configurations.includeInJar.collect { zipTree it }
}

However when I build Game it builds all of Cores dependencies into it. All the dependencies in the ‘compile’ configuration, not just the ones in includeInJar.

Does anyone know how I might be able to achieve my desired result?

(Edit: it should be noted that these projects are part of a multi project, that’s where the ‘java’ plugin is applied and what not)

Core build.gradle:

configurations {
    deps
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: '../Libraries')

    deps group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1'
}

jar {
    from configurations.compile.collect { zipTree it }
    from configurations.deps.collect { zipTree it }
}

Game build.gradle:

dependencies {
    compile fileTree(include: ['*.jar'], dir: '../Source')
}

jar {
    from configurations.compile.collect { zipTree it }
    from project(':Core').configurations.compile.collect { zipTree it }
}

I’m still pretty new to this Gradle stuff so take it with a grain of salt. Hope it helps or at least inspires a solution.

This will include all artifacts and dependencies from the ‘default’ configuration, which extendsFrom the runtime configuration, which extrendsFrom compile. The Java Plugin

If you want to depend on a specific configuration from another project, use:

includeInJar project(path: ':Core', configuration: 'includeInJar')