How I can include custom jars of subproject in root project?

I have a spring boot root-project which has multiple sub-projects/sub-modules. The Structure is as follows :

    - src
    - build.gradle
    - gradlew
    - settings.gradle
    - subproject A
    -subproject B

The root project’s build.gradle adds these two subprojects as dependencies :

dependencies {
  implementation (

The root-project.jar contains jars of these subprojects in BOOT-INF/lib folder.

I need to modify the subproject A and build two different jar files based on some project property. I was able to do so by adding the following
jar task in build :['channel'].split(',').each { channel ->

 def jarTask = task(channel+"Jar", type: Jar) {
    baseName = channel
    from (sourceSets.main.output) {
      if (channel == 'local'){
        exclude ('**/Service1.class')
      } else if(channel == 'prod'){
        exclude ('**/Service2.class')

  artifacts {
    archives jarTask

This task produces two jars in build/libs folder of subproject A as follows :
→ local.jar
→ prod.jar

How can I include these jars in the root project’s jar file ?

Basically I want two root project JAR files as follows :

root-project-local.jar - containing local.jar of subproject A
root-project-prod.jar - containing prod.jar of subproject A

I am a beginner in gradle :slightly_smiling_face: and not sure if this is possible. Please guide me in the right direction. Thanks! :smile:

Sounds like you should read about and use feature variants.