Composite Build and build hooks

Good day to all:

I am using Gradle 4.6

I have a parent project and a child project. Trying to use the composite build feature.

The child project has the following task in the build.gradle

afterEvaluate {
task fatJar(type: Jar) {
classifier = ‘fat’
from sourceSets.main.output
from {
configurations.runtimeClasspath.files.
findAll { it.name.startsWith(“aaa”) }.
collect { zipTree(it) }
}
exclude ‘META-INF/.RSA’, 'META-INF/.SF’, ‘META-INF/.DSA’, 'META-INF/.EC’
}
artifacts {
archives fatJar
}
build.dependsOn(fatJar)
}

When I call “./gradle build” directly on the child project, 3 files get generated: my.jar, my-fat.jar and my-sources.jar.

When I add includeBuild ‘…/child’ in the parent’s settings.gradle and run ./gradlew build from the parent, only one my.jar gets generated.
The fatJar never gets called.

What is the correct way of generating a fat jar from the parent project?

Thank you.

it is because (I think) building your parent project does not really depends on the build task of your child project. For your parent project to be built, all it needs from your child project is the artifact that can be used to substitute the dependency. Gradle will do the minimum to get that artifact produced, and the minimum is not the build task. build task has a larger scope - e.g. it runs unit tests - that is unnecessary if you just want to produce a jar (in the composite build case, in theory i think you dont even need the jar to be produced, all your truly need is the classes to be compiled and you can just include the path in the compile class path of your parent project).