On 30/12/2010, at 5:08 AM, paulcager wrote: > > I want to provide a "common" build initialisation script for all of our > project's gradle builds. The common script sets up our organisation's > defaults (such adding a "coverage" task etc) and the build.gradle scripts > can then call: > > apply from: "http://some-server/build-common.gradle" > > This works well except for one thing. I'd like to be able to change a > project's name within a build script like this: > > if (System.getenv("something")) { > project.name = "${project.name}-prod" > } > > This won't work as project.name is read-only. I realise I could do it in > settings.gradle, but I'd prefer not to have to force the users to set one of > these up. What's the best way to handle this sort of thing? > > Things I've tried that don't seem to work: > > * Setting project.name in buildScript{}. (Still read-only). > * Using --init-script "http://some-server/set-project-name.gradle" > (Doesn't allow URLs). > * Using -m "http://some-server/set-project-name.gradle" (Doesn't > allow URLs). > * Setting archivesBaseName instead of project.name. (successfully > changes the name of the Jar, but the upload to a repository still uses the > old name as the artefact name). > > Is there an easy way to do this?
You can only change a project's name in the settings.gradle script at the moment. You can, however, apply an external settings script from there, so the settings.gradle need only be a single line script with an apply statement. For the Gradle 1.0 release, we plan to merge the settings.gradle script into the build script, so you can do all this stuff in one place. -- Adam Murdoch Gradle Developer http://www.gradle.org CTO, Gradle Inc. - Gradle Training, Support, Consulting http://www.gradle.biz
