Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: How to share common tasks in multiproject build?

In my root build.gradle file I apply common tasks for all components:

apply from: rootProject.file('common/component.gradle')

In subproject i define componentTitle:

ext {
    componentTitle = 'application1'
 }

component.gradle:

jar {
    manifest {
        attributes 'Implementation-Title': componentTitle
    }
}

I am getting error:

A problem occurred evaluating script.
> No such property: componentTitle for class: org.gradle.api.java.archives.internal.DefaultManifest
like image 967
isobretatel Avatar asked Apr 29 '16 21:04

isobretatel


1 Answers

It seems, that you've applied this common configuration not only to subprojects, but to the root project too, though it doesn't have such a property. To apply it to subprojects only, configuration could be made like so:

subprojects {
    apply from: rootProject.file('/component.gradle')
}

But even now Gradle won't find the componentTitle property if you pass it the way you did (as a part of subproject script body). You need to make a gradle.properties file in all subprojects directories and move this property into this properties file, as usual:

componentTitle=application1

Then Gradle will be able to locate it during the configuration phase

like image 194
Stanislav Avatar answered Sep 21 '22 14:09

Stanislav