Use Properties from the root project in the subprojects


#1

I have a multi-project environment. In the root project I get the patchlevel from a file version.properties. I would then use these in the subprojects to generate the versionProperty

root build.gradle

task readversionInfo() {
	def versionPropsFile = file('version.properties')
    if (versionPropsFile.canRead()) {
        def Properties versionProps = new Properties()
        versionProps.load(new FileInputStream(versionPropsFile))

        ext.patchlevel = versionProps['PATCHLEVEL'].toInteger() + 1
        versionProps['PATCH'] = patchlevel.toString()
        versionProps.store(versionPropsFile.newWriter(), null)
    } else {
        throw new GradleException("Could not read version.properties!")
    }
}

build.gradle Subproject

if (project.hasProperty("patchlevel")	{
	println "Patchlevel is set"
	version = "${moduleversion}.${ext.patchlevel}.${svntools.info.revisionNumber}"
} else	{
	println "Patchlevel is not set"
	version = "${moduleversion}.0.${svntools.info.revisionNumber}"
}