Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composite build of 3 projects using gradle not working

Tags:

java

gradle

build

I am trying to create a composite build using gradle. I have 3 projects, lets say they are A, B and C. They share some modules and since I do not want gradle to build the same shared modules thrice that is why I am trying to create composite build. They have really complex build.gralde and settings.gradle files that is why I can not simply use gradle multiple project build. I have create top-project which contains this in settings.gradle:

rootProject.name = 'top-project'

includeBuild 'A'
includeBuild 'B'
includeBuild 'C'

My build.gradle looks like this.

task buildAll {
    dependsOn gradle.includedBuild('A').task(':build')
    dependsOn gradle.includedBuild('B').task(':build')
    dependsOn gradle.includedBuild('C').task(':build')
}

Every project - A, B and C can be built using ./PROJECT_NAME/gradlew build command. But when I am trying to run my defined task ./gradlew buildAll I got the error that:

Task with path ':build' not found in project ':B'

I think that is because project B does not have defined task build in his build.gradle file but his subprojects have this task that is why it will get built.

When I am trying to run my top level build.gradle with something like this:

dependsOn gradle.includedBuild('subproject-of-B').task(':build')

I will get an error like Project with path ... could not be found ... since it does know some properties defined in ./B/.settings.gradle etc.

So my question is, how can I easily create composite build of those 3 individual projects while their shared core will get built only once ?

Sorry if this is dumb question but I am really new to gradle and can not figure this out.

Thank you for any help.

like image 479
Druudik Avatar asked Oct 19 '25 10:10

Druudik


1 Answers

We faced the similar problem and found a possible solution. In your project A you should register a task (e.g. :runBuilds) that runs tasks :build from subprojects.

tasks.register("runBuilds") {
    dependsOn project.getTasksByName("build", true)
}

After that you'll be able to use that task in your root

dependsOn gradle.includedBuild("A").task(":runBuilds")
like image 91
IL_Agent Avatar answered Oct 21 '25 22:10

IL_Agent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!