Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /**
  2. * Print value of property provided in "-Pprop" on command line to stdout.
  3. *
  4. * Usage Example: ./gradlew -q printProperty -Pprop=rootProject.name
  5. */
  6. task printProperty {
  7. doLast {
  8. // get the "property name" in question from commandline:
  9. String prop = project.findProperty('prop')
  10. if (prop == null) {
  11. return // or use println ...
  12. }
  13.  
  14. // treat as property name:
  15. Object theProperty = project.findProperty(prop)
  16.  
  17. if (null == theProperty) {
  18. // try to handle provided information as "nested property"
  19. List<String> thePropPath = prop.split('\\.').toList()
  20.  
  21. theProperty = project.findProperty(thePropPath.head())
  22.  
  23. // aux. closure to travel "property path"
  24. def pp = { s, t ->
  25. if (s != null && s.hasProperty(t).is(true)) {
  26. return s.property(t)
  27. }
  28. return null
  29. }
  30. thePropPath.tail().each { item ->
  31. theProperty = pp(theProperty, item)
  32. }
  33. }
  34. println(theProperty ?: "") // or print "null" ...
  35. }
  36. }
  37.  
  38. /**
  39. * Prints value of property "rootProject.name" to stdout.
  40. *
  41. * Usage: ./gradlew -q printRootProjectName
  42. */
  43. task printRootProjectName {
  44. doLast {
  45. println(project.findProperty('rootProject').name)
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement