Hi all,
I have a problem I don’t quite understand. Probably it has something to do with the separation in configuration and execution phase.
I have a multi-project build that looks like this:
product
api
implementation
release-unix
release-osx
The release projects are being used to create distributions of the product. As the OS X release is almost the same as the Unix release all release logic is placed in the build.gradle file of the release-unix project which looks like this:
apply plugin: 'eclipse'
apply plugin: 'java'
dependencies { runtime project(':implementation') }
ext {
appFolder = ""
platform = "UNIX"
}
task configureRelease << {
println "New platform is: " + platform
rootProject.platform = platform
}
task prepareDistribution(type: Copy, dependsOn: configureRelease) {
println "App folder is: " + appFolder
from(configurations.runtime)
into("$buildDir/staging/" + appFolder + "lib/")
}
task distribution(type: Zip, dependsOn: [clean, configureRelease, prepareDistribution]) {
println "Platform is: " + platform
baseName = "product-name"
classifier = platform
from "$buildDir/staging/"
}
As you can see the logic is rather simple. The specified platform is applied to the root project and all dependent libraries are copied to the specified folder.
The release-osx build.gradle looks like this:
apply from: rootProject.project('release-unix').file('build.gradle')
ext {
println "Setting OSX variables"
appFolder = "Product.app/resources/"
platform = "OSX"
}
The only thing this file should do is change two external properties to generate the correct distribution format. But the problem is that neither the task ‘prepareDistribution’ nor the task ‘distribution’ use the newly defined platform and appFolder when executing ‘distribution’ in the release-osx project. The really strange thing about that is that ‘configureRelease’ shows and uses the correct platform though!
Here is the log output when executing ‘gradle distribution’ within the release-osx project:
[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts]
:release-osx:distribution
[sts] -----------------------------------------------------
App folder is:
Platform is: UNIX
Setting OSX variables
App folder is:
Platform is: UNIX
:release-osx:clean
:release-osx:configureRelease
New platform is: OSX
:api:assembleManifestClasspath
Platform for build of project 'api': OSX
:api:compileJava UP-TO-DATE
:api:processResources UP-TO-DATE
:api:classes UP-TO-DATE
:api:jar UP-TO-DATE
:implementation:assembleManifestClasspath
Platform for build of project 'implementation': OSX
:implementation:compileJava UP-TO-DATE
:implementation:processResources UP-TO-DATE
:implementation:classes UP-TO-DATE
:implementation:jar UP-TO-DATE
:release-osx:prepareDistribution
:release-osx:distribution
BUILD SUCCESSFUL
Total time: 2.501 secs
[sts] -----------------------------------------------------
[sts] Build finished succesfully!
[sts] Time taken: 0 min, 2 sec
[sts] -----------------------------------------------------
As you can see from the log the OS X variables are set after ‘distribution’ and ‘prepareDistribution’ have been configured once but even after setting the OS X variables the output is wrong. But when ‘configureRelease’ is called, the platform is correctly displayed and applied.
What exactly is going on in this case? Why do ‘distribution’ and ‘prepareDistribution’ use the wrong variables when being called from release-osx folder whereas ‘configureRelease’ uses the correct ones? I have absolutely no clue…
I’ve uploaded the described example project to https://bitbucket.org/ncwoehler/gradle-test/ if you want to have a closer look at it.
Any feedback is much appreciated
Best, Nils