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
isobretatel
  • 3,812
  • 7
  • 34
  • 49
  • try project.componentTitle or project.ext.componentTitle – AdamSkywalker Apr 30 '16 at 17:58
  • jar { manifest { attributes 'Implementation-Title': project.ext.componentTitle } } Error: Cannot get property 'componentTitle' on extra properties extension as it does not exist – isobretatel Apr 30 '16 at 23:33
  • jar { manifest { attributes 'Implementation-Title': project.componentTitle } } Error: Could not find property 'componentTitle' on root project – isobretatel Apr 30 '16 at 23:35

1 Answers1

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

Stanislav
  • 27,441
  • 9
  • 87
  • 82
  • I had to add fake property componentTitle=fakeValue to root project to avoid > No such property: componentTitle error in root script. – isobretatel May 11 '16 at 20:00
  • 1
    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 closure – Stanislav May 12 '16 at 09:10