How to filter out a certain portion of ./gradlew project:dependencies command?

十年热恋 提交于 2021-01-28 05:25:01

问题


Our build.gradle files have your normal depndencies block, like so..

dependencies {
    compile("com.myco.service:service-discovery:+")
    compile("com.myco.common:some-common:1.0.84")
    compile("com.myco.cms:cms-service-client:1.0.145")
    compile("com.myco.stats:some123-stats-service-client:1.0.140")
    ...
}

I run this to get the dependency tree

$ ./gradlew project:dependencies | grep com\.myco | sort | uniq

and get

+--- com.myco.canam:canam:0.1.4
+--- com.myco.cms:cms-service-client:1.0.145 (*)
+--- com.myco.common:some-common:1.0.84
+--- com.myco.crm:crm.ansira:0.0.1
+--- com.myco.somehtml:somehtmlcleaner:0.0.1
|         +--- com.myco.common:some-common:1.0.79 -> 1.0.84 (*)
|         +--- com.myco.security:security-service-client:1.0.107 -> 1.0.134 (*)
|    +--- com.myco.common:some-common:1.0.58 -> 1.0.84 (*)
|    +--- com.myco.common:some-common:1.0.80 -> 1.0.84 (*)

I want to get ALL the lines that do not start with the | character. It just so happens that all these lines also end with (*) characters, so I add a sed pipe, like so

./gradlew project:dependencies | sed 's/^.* //' | grep com\.myco | sort | uniq

and get

com.myco.canam:canam:0.1.4
com.myco.common:some-common:1.0.84
com.myco.crm:crm.ansira:0.0.1
com.myco.somehtml:somehtmlcleaner:0.0.1

which is exactly what I want, except that this line is missing

com.myco.cms:cms-service-client:1.0.145

because it so happens to end with the (*) characters. What is a better sed (or awk) expression so I get

com.myco.canam:canam:0.1.4
com.myco.cms:cms-service-client:1.0.145
com.myco.common:some-common:1.0.84
com.myco.crm:crm.ansira:0.0.1
com.myco.somehtml:somehtmlcleaner:0.0.1

回答1:


Seems like this might be what you want (using cat file instead of ./gradlew project:dependencies since I don't have that command):

$ cat file | awk '/^\+.*com\.myco/ && !seen[$2]++{print $2}'
com.myco.canam:canam:0.1.4
com.myco.cms:cms-service-client:1.0.145
com.myco.common:some-common:1.0.84
com.myco.crm:crm.ansira:0.0.1
com.myco.somehtml:somehtmlcleaner:0.0.1


来源:https://stackoverflow.com/questions/57700382/how-to-filter-out-a-certain-portion-of-gradlew-projectdependencies-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!