This is an updated question for How to filter out a certain portion of ./gradlew project:dependencies command? (version 2)
I'm writing a routine that parses the dependencies{} portion of a build.gradle file, which may look like this
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.
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
+ --- 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
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.
com.groupId:artifact0:1.0.0
com.groupId:artifact1:2.1.0
com.groupId:artifact2:3.0.0