Quantcast

Is this correct use of init.gradle? (passing properties to be used in build.gradle)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Is this correct use of init.gradle? (passing properties to be used in build.gradle)

philippj
Dear Gradle Community
(Repost into the correct user group gradle-user, instead of nabble)

I'm new to Gradle and I'm using Gradle 0.9.2.

I found http://www.gradle.org/0.9.2/docs/userguide/init_scripts.html and I wanted to do some per environment scripting with init.gradle

I wanted to do a some basic Groovy scripting (figuring out which spring-context.xml to add to the build path) and pass this information into the build. I'm aware that there are gradle.properties to achive similar things, but I wanted to do some additional Groovy scripting, so using init.gradle seems to be the way.

This was surprisingly hard.
The user guide, Google, did not help very much. Essentially the main information I got was the one line from:
http://www.gradle.org/0.9.2/docs/dsl/index.html
"Init script (delegates to instance of) Gradle"

so after some try and error I came up with this init.gradle:
'''
println 'foos init.gradle is being executed'

gradle.beforeProject {
        it.environmentSpecificClassPathFormInitScript = 'src/main/environments/foo'
}
'''

so my question: Is this the correct use of init.gradle if I want to pass a value into the build.gradle?

If yes: please consider documenting it a bit better at
I found http://www.gradle.org/0.9.2/docs/userguide/init_scripts.html
as this page documents special cases like dependencies but not the very basic
Please consider including the the words "switching environments" somewhere in the user guide or tutorials or FAQ as it was really hard to find via Google.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is this correct use of init.gradle? (passing properties to be used in build.gradle)

Peter Niederwieser
philippj wrote
so my question: Is this the correct use of init.gradle if I want to pass a value into the build.gradle?
It might be easier to do the scripting in the root project's build script. The current environment could be set in gradle.properties or passed as command-line argument.

--
Peter Niederwieser
Developer, Gradle
http://www.gradle.org
Trainer & Consultant, Gradle Inc.
http://www.gradle.biz
Founder, Spock Framework
http://spockframework.org



Loading...