I'm having a slight problem with the execution order.
I like how goals in maven are attached to a lifecycle. I thought this would be trivial to replicate in gradle using tasks and dependsOn but things aren't working quite the way I had hoped.

Here is an example:

-------------- build.gradle --------------


// default lifecycle (based on maven lifecycle)
task validate
task initialize( dependsOn: validate )
task generateSources( dependsOn:  initialize )
task processSources( dependsOn:  generateSources )
task generateResources( dependsOn:  processSources )
task processResources( dependsOn:  generateResources )
task compile( dependsOn:  processResources )
task processClasses( dependsOn:  compile )
task generateTestSources( dependsOn:  processClasses )
task processTestSources( dependsOn:  generateTestSources )
task generateTestResources( dependsOn: processTestSources )
task processTestResources( dependsOn: generateTestResources )
task testCompile(dependsOn: processTestResources )
task processTestClasses(dependsOn: testCompile )
task test(dependsOn: processTestClasses )
task preparePackage(dependsOn: test )
task createPackage( dependsOn: preparePackage )
task preIntegrationTest( dependsOn: createPackage )
task integrationTest( dependsOn: preIntegrationTest )
task postIntegrationTest( dependsOn: integrationTest )
task verify( dependsOn: postIntegrationTest )
task install( dependsOn: verify )
task deploy( dependsOn: install )


task beforeMsBuild << {
        println "Executing beforeMsBuild"
}
task msbuild(dependsOn: beforeMsBuild) << {
        println "Executing MSBuild"
}

task generateSolutionVersionInfo << {
        println "Creating solution version info"
}


generateSources.dependsOn generateSolutionVersionInfo
compile.dependsOn msbuild


-------------- output --------------

:msbuild
Executing MSBuild
:generateSolutionVersionInfo
Creating solution version info
:validate UP-TO-DATE
:initialize UP-TO-DATE
:generateSources
:processSources
:generateResources
:processResources
:compile

BUILD SUCCESSFUL

----

My intention here was to execute these tasks as part of that lifecycle phase, and I expected that the task dependencies would be executed in-order defined. Howerver, in this case, msbuild is being executed before generateSolutionVersionInfo.

Technically, speaking msbuild does not depend on any tasks, so from a DAG perspective this one correct solution to the stated dependencies, but not the one I'm looking for.

I could change msbuild to dependsOn the processResources task, but I wanted the reason I did not do this is because I wanted to keep the lifecycle and implementation separate as maven does. In some cases I may want to run "gradle msbuild" directly without executing any other tasks, but adding a dependsOn processResources would force execution of the lifecycle up to processResources which is not what I want.

Another way to approach this is perhaps to use execute() instead of dependsOn.

generateSources << { generateSolutionVersionInfo.execute() }
compile << { msbuild.execute() }


However if I use execute the dependsOn is not processed at all and the tasks are never added to the taskGraph and beforeMsBuild is not executed which prevents me from creating mini-lifecycles.

------- output -------

W:\build-sandbox\test>gradle compile
:validate UP-TO-DATE
:initialize UP-TO-DATE
:generateSources
Creating solution version info
:processSources
:generateResources
:processResources
:compile
Executing msbuild

BUILD SUCCESSFUL


Is there another way to go about this?




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

   http://xircles.codehaus.org/manage_email


Reply via email to