gradle - Creating a static global varible that I can increment in subprojects -
gradle - Creating a static global varible that I can increment in subprojects -
i have project many sub-projects.
in parent project need define variable port. each time subproject executes particular task, need increment port (thereby ensuring port number never used twice run in --parallel).
how do this?
update clarityso project construction this
parent - |->sub-project-1 | |->sub-project-2 the parent project should define initial port number.
project.ext.portnumber = 4200 //set global port number somehow in each sub-project want utilize port number
project.portnumber++; //increment in way println "${project.name} using port: ${project.portnumber}" so running gradlew build on parent project output:
sub-project-1 using port: 4201 sub-project-2 using port: 4202 if run gradlew build while within parent/sub-project-2 get
sub-project-2 using port: 4201 as each project builds need portnumber static property in java, ie. available sub-projects , not reset.
if understand correctly need each sub-project assigned port number, regardless of whether you're running total build root project or within of sub-project.
therefore, you'll have calculate port number projects in every execution of gradle.
the next code:
ext.portnumber = 4200 gradle.projectsevaluated { g -> g.rootproject.subprojects { p -> p.ext.portnumber = gradle.rootproject.portnumber++ println "$p.name [$p.portnumber]" } } executed against next project structure
parent - |->proja - |->proja1 |->proja2 |->projb yielded next output whether executed root project or 1 of sub-project:
proja [0] projb [1] proja1 [2] proja2 [3] one note - admit did not check solution extensively --parallel flag. however, projectsevaluated hook called before task graph beingness populated possible --parallel not impact configuration. in case believe can sync access root project portnumber using of java standard synchronization mechanism.
gradle
Comments
Post a Comment