On 06/09/2011, at 5:11 PM, Mathias Åhsberg wrote:

> I am trying to set up a multi-project build for a Grails project and want to 
> use Cargo (cargo-gradle-plugin) to deploy my application to a tomcat 
> container.
> 
> I have made it work by including the following into my main build.gradle file:
> 
> war {
>       exec {
>       executable = getGrailsExecutable()
>       args = ['war']
>       workingDir = project(':application').projectDir
>       }
>       from 
> zipTree(project(':application').file("target/${applicationName}-${version}.war"))
>       }
> 
> which executes the grails war command in the application sub-project and then 
> uses the war file to generate a new war file when the war task is called.
> 
> When I run the command cargoRedeployRemote this setup generates a war file 
> and deploys it to the configured container as expected. However, the war task 
> is executed upon all other task calls as well. 
> For example if I run the ./gradlew test gradle will execute my grails war 
> command before running the tests. 
> 
> If I change to the following structure the war task is only called when I 
> specifically call the ./gradlew war task, but this section is never called 
> when I execute the ./gradlew cargoRedeployRemote task.
> 
> war << {
> ...
> }
> 
> So my questions are: 
> 1. How do I make my war task to not execute when other tasks (that do not 
> include the war task in the taskGraph) are called?

It's being executed every time because you are calling Grails during the 
configuration phase.

war {
        // stuff in here configures the war task and runs during configuration 
(i.e. always)
}

vs. 

war << {
        // stuff in here gets run when the war task runs
}

So what you really want is:

war {
        doFirst {
                exec {
                executable = getGrailsExecutable()
                args = ['war']
                workingDir = project(':application').projectDir
        }
        from 
zipTree(project(':application').file("target/${applicationName}-${version}.war"))
}

> 2. How can I make my war task to be simpler. I think it is unnecessary that 
> grails first creates a war file, and then gradle will unpack the war file and 
> generate a new one.

This is going to be a little difficult because of the way the cargo plugin is 
written. It's assuming very deep down that it's only going to be used with the 
War plugin. Without that changing, the approach you are using is going to be 
the simplest.

-- 
Luke Daley
Principal Engineer, Gradleware 
http://gradleware.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to