问题
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