groovy - How to extend the behavior of a Gradle task for a new task type? -


i set few things few test tasks. more specifically, add few environment variables , few system properties, maybe few other things such "dependencies" or "workingdir". regular test task can this,

task test1(type:test, dependson:[testprep,testprep1]){      workingdir testworkingpath      systemproperty 'property','abs'      environment.find { it.key ==~ /(?i)path/ }.value += (system.properties['path.separator'] + mylibpath)      environment.ld_library_path = "/usr/lib64:/lib64:${mylibpath}:" + environment.ld_library_path  }  task test2(type:test, dependson:[testprep]){      workingdir testworkingpath      systemproperty 'property','abs'      environment.find { it.key ==~ /(?i)path/ }.value += (system.properties['path.separator'] + mylibpath)      environment.ld_library_path = "/usr/lib64:/lib64:${mylibpath}:" + environment.ld_library_path      systempropety 'newproperty','fdsjfkd'  } 

it nice have new task type mytesttype extending regular test task type, common definition defined.

task test1(type:mytesttype){      dependson testprep1  }  task test2(type:mytesttype){      systempropety 'newproperty','fdsjfkd'  }  

what best way this? seems execute() method final , cannot extended. need dofirst set properties. should add values in constructor? there other hook can use? thanks.

in general can extend 'test' task , implement customizations

task test1(type:mytesttype){ }  task test2(type:mytesttype){      systemproperty 'newproperty','fdsjfkd' }  class mytesttype extends test {     public mytesttype(){         systemproperty 'property','abs'     } } 

alternatively can configure tasks of type test less boilerplate:

// apply tasks of type test.  // regardless task created before snippet or after tasks.withtype(test) {    systemproperty 'newproperty','fdsjfkd'    } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -