How to make gradle task ShadowJar also create sources and javadoc of your children?

I have a gradle project with 8 child projects and a configured shadowjar task to create an β€œall” jar. The toplevel project is configured to have dependencies with all its children, this tells shadowjar what to include:

project(':') { dependencies { compile project(':jfxtras-agenda') compile project(':jfxtras-common') compile project(':jfxtras-controls') compile project(':jfxtras-icalendarfx') compile project(':jfxtras-icalendaragenda') compile project(':jfxtras-menu') compile project(':jfxtras-gauge-linear') compile project(':jfxtras-font-roboto') } } shadowJar { classifier = null // do not append "-all", so the generated shadow jar replaces the existing jfxtras-all.jar (instead of generating jfxtras-all-all.jar) } 

This works fine, but the central part of maven discards all jars because it does not have any related sources and javadocs jar.

How to tell gradle to also generate sources and javadoc? The ShadowJar documentation says that it should do this by default.

+7
java gradle shadowjar
source share
1 answer

The shadow plugin does not seem to have the ability to create jars with bold sources / javadocs.

Below I provide a few short tasks ( javadocJar and sourcesJar ) that will build live javadoc and source banks. They are bound to always execute after shadowJar . But it has nothing to do with the shadow banner plugin.

 subprojects { apply plugin: 'java' } // Must be BELOW subprojects{} task alljavadoc(type: Javadoc) { source subprojects.collect { it.sourceSets.main.allJava } classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath }) destinationDir = file("${buildDir}/docs/javadoc") } task javadocJar(type: Jar, dependsOn: alljavadoc) { classifier = 'javadoc' from alljavadoc.destinationDir } task sourcesJar(type: Jar) { classifier = 'sources' from subprojects.collect { it.sourceSets.main.allSource } } shadowJar.finalizedBy javadocJar shadowJar.finalizedBy sourcesJar 

Please note: the subprojects section subprojects required even if you already use the java plugin inside your subprojects.

Also note that it does not include third-party javadocs that your subprojects may affect. But as a rule, you would not want to do this anyway, perhaps.

+4
source share

All Articles