Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Print value of property provided in "-Pprop" on command line to stdout.
- *
- * Usage Example: ./gradlew -q printProperty -Pprop=rootProject.name
- */
- task printProperty {
- doLast {
- // get the "property name" in question from commandline:
- String prop = project.findProperty('prop')
- if (prop == null) {
- return // or use println ...
- }
- // treat as property name:
- Object theProperty = project.findProperty(prop)
- if (null == theProperty) {
- // try to handle provided information as "nested property"
- List<String> thePropPath = prop.split('\\.').toList()
- theProperty = project.findProperty(thePropPath.head())
- // aux. closure to travel "property path"
- def pp = { s, t ->
- if (s != null && s.hasProperty(t).is(true)) {
- return s.property(t)
- }
- return null
- }
- thePropPath.tail().each { item ->
- theProperty = pp(theProperty, item)
- }
- }
- println(theProperty ?: "") // or print "null" ...
- }
- }
- /**
- * Prints value of property "rootProject.name" to stdout.
- *
- * Usage: ./gradlew -q printRootProjectName
- */
- task printRootProjectName {
- doLast {
- println(project.findProperty('rootProject').name)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement