[Solved] How to parse gradlew output to get artifact version?

Chris F Asks: How to parse gradlew output to get artifact version?
I’m writing a routine that parses the dependencies{} portion of a build.gradle file, which may look like this

Code:
dependencies {
  compile "com.groupId:artifact0:1.0.0"
  compile "com.groupId:artifact1:2.+"
  compile "com.groupId:artifact3:3.+"
  compile "org.otherGroupId:artifact:1.0.0"
}

Now I run a Jenkins pipeline (Groovy) script that does the following. The awk takes all the lines that start with “+” character in column 1, and has “com.groupId” string. What I’m calling “other data” are lines that neither have “+” in column 1, nor the “com.groupId” string, the awk script ignores those.

Code:
sh "./gradlew project:dependencies | tee deps.txt"
List depList = sh(script: " awk -F '[: ]+' -v OFS=: '/^\+.*com\.groupId/ && !seen[$2,$3]++{print $2, $3, $4}' deps.txt",
                  returnStdout: true).split("n")

My deps.txt shows

Code:
+ --- com.groupId:artifact0:1.0.0
... other data
+ --- com.groupId:artifact1:2.+ -> 2.1.0
... other data
+ --- com.groupId:artifact2:3.+ -> 3.0.0 (*)
... other data
+ --- org.otherGroupId:artifact:1.0.0
... other data

and my List depList looks like

Code:
com.groupId:artifact0:1.0.0
com.groupId:artifact1:2.+
com.groupId:artifact2:3.+

which is exactly what I asked awk to do correct? Note the 4th dependency is not there, again because of my awk statement.

But how can I modify the awk script to get the actual version values, so my depList shows this? In other words, I want it to get the resolved versions obtained by the dependencies Gradle task.

Code:
com.groupId:artifact0:1.0.0
com.groupId:artifact1:2.1.0
com.groupId:artifact2:3.0.0

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.