Gradle: How to share common tasks in multiproject build?
Asked Answered
T

1

9

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
Tatro answered 29/4, 2016 at 21:17 Comment(3)
try project.componentTitle or project.ext.componentTitleTroopship
jar { manifest { attributes 'Implementation-Title': project.ext.componentTitle } } Error: Cannot get property 'componentTitle' on extra properties extension as it does not existTatro
jar { manifest { attributes 'Implementation-Title': project.componentTitle } } Error: Could not find property 'componentTitle' on root projectTatro
O
4

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

Overflow answered 10/5, 2016 at 11:12 Comment(2)
I had to add fake property componentTitle=fakeValue to root project to avoid > No such property: componentTitle error in root script.Tatro
It's all because you've applied it to the root script, though it doesn't need it. That is the reason to use apply from within subprojects closureOverflow

© 2022 - 2024 — McMap. All rights reserved.