Using properties from subproject in "subprojects" : Could not find property 'something' on project ':subproject'


(Hertel) #1

Hi,
I have a project with subprojects, and I want to define that the manifest file for all subproject jars contains the same format of metadata (but eg. with different versions):

subprojects {
apply plugin: ‘java’

jar {
manifest {
attributes(“Implementation-Title”: “sometext”,
“Implementation-Vendor”: “company name here”,
“Build-Timestamp”: project.tstamp,
“Implementation-Version”: “${project.projectversion}.${project.revision}”)
}
}
}

Now in each subproject I define:
project.ext {
projectversion = "1.2"
revision = "12321"
tstamp = “eg. get date by new Date().toString()”
}

But I always get:

Could not find property ‘tstamp’ on project ‘:subproject’.

Why is that? - Perhaps this is a newbie question, but I don’t seem to grasp it. Why are the project.ext properties in the subprojects not evaluated?


(Stefan Oehme) #2

The subproject’s build script runs after the root project, that’s why the properties are not there yet. You can work around this by making sure you evaluate them lazily:

BTW, there already is a version attribute on the Gradle project by default, no need to design your own :slight_smile:


(Hertel) #3

I tried your suggestion, using “${…}”, but this still doesn’t work:

A problem occurred evaluating root project 'Name'.
> Could not find property 'tstamp' on project ':commonLib'.

You are of cause right about the project version, I will change that.

Perhaps my question is wrong. What i want to achieve, is define a template for jar generation, where certain things are always set in the same way, eg. the “Implementation-Version” should always contain the SVN revision, but the revision might be different for each subproject (different repositories!). On the other hand, the “Implementation-vendor” should always be the same, and I do not want to define it in each build.gradle file.