Hi rt, Am 28.12.10 06:45, schrieb rt.rich: > I am trying to convert a fairly complex Ant build script that also > incorporates Maven tasks into a unified Gradle build. The end-product of the > build is to generate at least one, and up to two WAR files, which are > basically the same, except for some configuration settings files. > > We have a set of files that define the properties for each particular > deployed machine, of the name <machine>.properties. They containing property > definitions of the format "{env}.{setting}=value" where {env} can be one of > the two application environment prefixes we use (for purposes of this > example, we could just call them "foo" and "bar" - so typical lines would be > like > > foo.dbName=PROD01 > foo.dbHost=db23.foo.com > bar.dbName=TEST55 > bar.dbHost=db24.test.foo.com > > and so on. If a machine has an environment disabled, there is just one > entry: > > foo.disabled=true > > and so we don't create any env-specific configuration files from the > templates and > properties, nor the final 'foo.war'. > > So far, my Gradle script has an 'all' task, which just does a simple loop of > the form > ['foo', 'bar'].each { env -> .....} > > in which it processes the above configuration file, creates a Properties > object with the "{env}." prefix stripped out for the keys, and then calls a > small Groovy method called gen_config(envName, props) to create the various > env-specific XML files in 'target/tmp-${env}'. The 'all' task has a > dependency on 'compileJava', so my classes have already been built. However, > at this point, I am not able to figure out how to manually invoke the 'war' > task to build one or both of 'foo.war' and/or 'bar.war', using the contents > of 'target/classes' and 'target/${env}-tmp'. > > I have read and re-read the manual and list archives, in particular, about > the Configuration and Execution phases but still don't understand if it's > possible to create dynamic separate tasks to build 'foo.war' and 'bar.war', > given that my 'all' task is already running, and I believe it is too late to > attach a dependency to it. Can I simply invoke the 'war' task manually with > the configuration specifiers to use the necessary files? > > I did attempt doing something like > task buildWar(type: War, envName, props) { ...} > with the hope that I could pass arguments in the task invocation, but had no > success. Can Tasks > have argument lists?
You can't pass arguments to your task definition this way. You could dynamically create war different war tasks for each configuration: ["kung", "foo", "bar", ].each{env -> task "${env}War"(type:War){ baseName = "${env}" from "target/${env}-tmp" } } to create the specific war task just if no "foo.disabled" is set in your configuration file, you can use the groovy configslurper like in your build script Properties props = new Properties(); FileInputStream fis = new FileInputStream(file("configs/allconfigs.properties")); props.load(fis); fis.close(); project.envconfigs = new ConfigSlurper().parse(props) //store config slurper instance as project property and create the accordant war tasks with this a tiny modification of the snippet: task processConfig { doLast{ // create environment specific xml files //... //... } } ["kung", "foo", "bar"].each{env -> if(!project.envconfigs."${env}".disabled){ task "${env}War"(type:War){ baseName = "${env}" from "target/${env}-tmp" } } } when you call "gradle assemble" now, only the configured war archives are created. does this basically fit your needs? regards, René > Thanks for any help you can give. > > Rich -- ------------------------------------ Rene Groeschke r...@breskeby.com http://www.breskeby.com http://twitter.com/breskeby ------------------------------------ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email