Posted By

laurenceosx on 01/30/12


Tagged

hack groovy gradle


Versions (?)

Groovy Gradle hack for keeping dependsOn execute order.


 / Published in: Groovy
 

Dummy comment to make this snippet visible.

  1. def synchronized orderTasks( String aTasks ) {
  2. // Laurence Toenjes 2012
  3. // preserve dependency task order for Gradle (put this near the top of your gradle build file)
  4. // example: task( 'seq-alpha', dependsOn: orderTasks( 'alpha bravo charlie' ) ) << { /* your task code */ }
  5. // To view task dependency do cmd: gradle tasks --all
  6. if ( !(project.ext.properties.containsKey("orderTasksCtr")) )
  7. project.ext.orderTasksCtr = new java.util.concurrent.atomic.AtomicInteger(1000);
  8. def cl_createProxyTask = { aTaskName ->
  9. def ctr = project.ext.orderTasksCtr.incrementAndGet();
  10. def newTaskName = "_seq_${ctr}_${aTaskName}";
  11. def newTask = project.task( newTaskName );
  12. newTask.dependsOn << "${aTaskName}";
  13. def result = newTask;
  14. }
  15. ''' , ' " [ ] ( ) '''.trim().split().each {
  16. if (it in aTasks)
  17. aTasks = aTasks.replace( it, (32 as char).toString() )
  18. }
  19. return aTasks.split().collect { cl_createProxyTask(it) };
  20. }
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23.  
  24. def calcSubTasks( aTask ) {
  25. // used by taskInfo
  26. def st = ( aTask.dependsOn.collect {it} as List ).flatten();
  27. def filter1 = ( st.findAll { !("$it" == 'file collection') } );
  28. return filter1;
  29. }
  30.  
  31. def taskInfo( aTask, aLevel = -1 ) {
  32. // use this recursive routine to print out an indented task dependency.
  33. // example call: taskInfo( 'someTaskName' );
  34. // uses calcSubTasks( aTask )
  35. aLevel++;
  36. def SPACE = "${32 as char}"
  37. def indent = (SPACE*2) * aLevel;
  38. print indent;
  39. def skip = "${aTask.name}".startsWith("_seq_");
  40. if (!skip)
  41. println "${aTask.name}";
  42. calcSubTasks( aTask ).each {
  43. def theTask = (it instanceof org.gradle.api.internal.AbstractTask) ? it : project.tasks[ "$it" ] ;
  44. taskInfo( theTask, aLevel )
  45. }
  46. }

Report this snippet  

You need to login to post a comment.