On 02/05/2011, at 5:47 AM, Marco Hunsicker wrote:
>>> You'll have to add another Compile task and configure it manually
>>> (copy the configuration over from compileJava).
>
> Hm, how do I do that? I was thinking I could simply trigger the compileJava
> task of the root project and Gradle would to the rest. But I cannot find a
> way to do just that. How do I apply the configuration to the new task?
>
> I've found a way to achieve the goal: manually invoking the compile tasks of
> all projects, setting all properties manually, but there must be a better
> way, or isn't it?
>
>
> allprojects.each { subproject ->
> // what to do with the original configuration?
> Configuration config = subproject.configurations.getByName("compile")
>
> Compile task = subproject.tasks.getByName("compileJava")
>
> Compile task2 = subproject.tasks.add("recompileJava", Compile.class)
> task2.setConvention(task.convention)
> task2.setSource(task.source)
> task2.setClasspath(task.classpath)
> ...
> task2.execute()
> }
>
> If I do the above just for the root project, nothing compiles as the source
> set for the root project is empty.
Calling execute() on a task is something we don't really recommend. I think
instead you should use task dependencies. Then you can simply use the standard
lifecycle tasks such as 'gradle assemble', and your source is compiled twice,
as needed.
Here's an example:
In your root build script (not in the body of a task):
allprojects {
task recompileJava(type: Compile) {
dependsOn compileJava
source = compileJava.source
classpath = compileJava.classpath
....
}
classes dependsOn recompileJava
}
--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com