Compiling subproject jars twice

I have a multi project build, which has 5 sub projects like a,b,c,d and e. project b depends on a, c depends on b and d depends on c. project e is building war which is includes a,b,c,d. build is compiling all sub projects individually and also compile once again when it’s creating war. I just want to reuse the sub project jar once they are build when creaing war instead of compiling them again.

thanks in advance.

Hello,

The default behavior is to assemble each project once:

settings.gradle

include 'a', 'b', 'c', 'd', 'e'

build.gradle

subprojects {
	apply plugin: 'java'
	repositories {
		mavenCentral()
	}
}

configure(subprojects.find { it.name == 'b' }) {
	dependencies {
		implementation project(':a')
	}
}

configure(subprojects.find { it.name == 'c' }) {
	dependencies {
		implementation project(':b')
	}
}

configure(subprojects.find { it.name == 'd' }) {
	dependencies {
		implementation project(':c')
	}
}

configure(subprojects.find { it.name == 'e' }) {
	apply plugin: 'war'
	dependencies {
		implementation project(':d')
	}
}
$ gradle -m assemble
:a:compileJava SKIPPED
:a:processResources SKIPPED
:a:classes SKIPPED
:a:jar SKIPPED
:a:assemble SKIPPED
:b:compileJava SKIPPED
:b:processResources SKIPPED
:b:classes SKIPPED
:b:jar SKIPPED
:b:assemble SKIPPED
:c:compileJava SKIPPED
:c:processResources SKIPPED
:c:classes SKIPPED
:c:jar SKIPPED
:c:assemble SKIPPED
:d:compileJava SKIPPED
:d:processResources SKIPPED
:d:classes SKIPPED
:d:jar SKIPPED
:d:assemble SKIPPED
:e:compileJava SKIPPED
:e:processResources SKIPPED
:e:classes SKIPPED
:e:war SKIPPED
:e:assemble SKIPPED

There must be something particular in your build that defeat the default behavior.

1 Like

Note: Instead of

configure(subprojects.find { it.name == 'b' }) {
  ... 
}

You can do

project(':b') {
  ... 
}
1 Like

thanks for you reply.
able to build the jar but it’s still creating duplicate jar i.e it’s building sub project jars twice.

Hi,
I have added all 4 subprojects in the war project since it’s failing to create the war due to the dependency issue.
configure(subprojects.find { it.name == ‘e’ }) {
apply plugin: ‘war’
dependencies {
implementation project(’:a’)
implementation project(’:b’)
implementation project(’:c’)
implementation project(’:d’)
}
}