Multi project configuration artifacts jar failed to be included in a root war

Hi,

I found my build script works well in version 2.3 and 2.4, but runs failed in version 2.5~2.7.

Please help me to figure out where the problem exists.

My multi-projects try to build a root war file to include all subprojects’ artifact jars.

Directory just like this

/root/build.gradle
/subproject1/build.gradle
/subproject2/build.gradle
/.../

And the following are settings and scripts:

root/settings.gradle

def projects = [
	'ka'
	]

for (proj in projects) {
	include proj
	
	project(":" + proj).projectDir = new File("../" + proj)
}

root/build.gradle

dependencies {
	subprojects.each { p ->
		compile project(path: p.path, configuration: 'warLibs')
		compile project(path: p.path, configuration: 'compile')
	}
}

ka/build.gradle

configurations {
	warLibs
}

sourceSets{	
	api {
		// just ignore
	}
	
	core {
		// just ignore
	}
}

task apiJar(type: Jar) {
	archiveName "$projectName-api-$version" + ".jar"
	from sourceSets.api.output
}

task coreJar(type: Jar, dependsOn: apiJar) {
	archiveName "$projectName-core-$version" + ".jar"
	from sourceSets.core.output
}

artifacts {
	warLibs apiJar
	warLibs coreJar
}

The expected result is a war file in this layout

root.war/
--WEB-INF/
---- lib/
------ ka-api-1.0.jar
------ ka-core-1.0.jar

but since Gradle version 2.5, the war file layout change to

root.war/
--WEB-INF/
---- lib/
------ ka-api-1.0.jar

I don’t know why the second jar, ka-core-1.0.jar, disappered…

I also see the release notes from version 2.5, 2.6, 2.7, and didn’t find any description about it.

Please help, thank you.

Sincerely,
Micky

When I run gradle build like:

gradle clean war

output is

:clean
:ka:clean
:ka:compileJava
:ka:processResources
:ka:classes
:ka:compileApiJava
:ka:processApiResources
:ka:apiClasses
:ka:apiJar
:ka:compileCoreJava
:ka:processCoreResources
:ka:coreClasses
:ka:coreJar
:compileJava
:processResources
:classes
:war
:ka:war

BUILD SUCCESSFUL

Total time: 14.219 secs

The coreJar task runs, and the ka-core-1.0.jar and ka-api-1.0.jar are both generated in ka/build/libs.

Just very strange, the ka-core-1.0.jar didn’t to be included in generated war file.

@@"

Can anybody confirm this is a bug or not?!

Or just give me some suggestions to achieve my target.

Many thanks :slight_smile:

Unfortunately I’m unable to reproduce the behavior you are seeing. Are you doing any kind of filtering on your WAR? Perhaps try adding a debug statement to see if these JARs are indeed being added to the correct configuration.

war {
    doFirst {
        println "War classpath: $classpath.asPath"
    }
}

Hi mark,

I try your script, and found that the print result is only have ka-api-1.0.jar in classpath.

And if I try to switch ka-api-1.0.jar to second, then the ka-core-1.0.jar in classpath.

What I mean is
if I change the sequence in artifacts, only the first one will be included in classpath.

artifacts {
	warLibs apiJar
	warLibs coreJar
}

==> only apiJar in root war classpath

artifacts {
	warLibs coreJar
	warLibs apiJar
}

==> only coreJar in root war classpath

It’s really strange.

And I also tried

ka/build.gradle

artifacts {
	warLibs1 apiJar
	warLibs2 coreJar
}

with
root/build.gradle

dependencies {
	subprojects.each { p ->
		compile project(path: p.path, configuration: 'warLibs1')
		compile project(path: p.path, configuration: 'warLibs2')
		compile project(path: p.path, configuration: 'compile')
	}
}

==> only first configuration will be adopted. in this sample, it’s apiJar in root war classpath

And the same configuration works very well in version 2.3 and 2.4, but runs failed in version 2.5~2.8.

Anybody knows why?

Hi,

I upload the sample project and build script as attachment.

Just unzip it, and run command in the deploy-full directory as following

[deploy-full]#> gradle war

The correct result is ka-core-latest.jar and ka-api-latest.jar both in deploy-full.war by running gradle below version 2.4.

The incorrect result is only ka-api-latest.jar in deploy-full.war by running gradle above version 2.5.

Please help to verify, thank you.

sample.zip (4.7 KB)

Thanks for the sample @mickyp. We are going to look into this issue.

Thanks for the reproducible sample @mickyp. I’ve narrowed this down to the use of archiveName for multiple artifacts in the depended-on project.

I’ve raised GRADLE-3362 for this issue, and am doing some further investigation.

In the meantime, you could switch your Jar tasks to use the baseName property instead of archiveName, and you should get both artifacts included in the resolved configuration.

1 Like

Thanks, @daz. You should be able to get the same result by simply setting the jar task’s appendix property.

task apiJar(type: Jar) {
	appendix "api"
	from sourceSets.api.output
}

task coreJar(type: Jar, dependsOn: apiJar) {
	appendix "core"
	from sourceSets.core.output
}
1 Like

Or you could just wait for Gradle 2.10. Fix is in master!

Wow~~

It’s really solved by using appendix!!

And looks like I don’t need archiveName anymore.

Thanks for your help @mark_vieira @daz.

test archiveName on 2.10-rc1, it works perfectly!