gpt4 book ai didi

bash - 如何过滤掉./gradle project:dependencies命令的特定部分? (版本2)

转载 作者:行者123 更新时间:2023-12-03 03:56:11 24 4
gpt4 key购买 nike

我不久前发布了How to filter out a certain portion of ./gradlew project:dependencies command?并实现了给出的可接受答案。但是,似乎给了我错误的信息。

我有以下(简体)build.gradle文件

dependencies {
implementation("com.myco.security:security-service-client:1.0.199")
}

当我运行命令
$ ./gradlew :project:dependencies | tee deps.txt

我在 deps.txt文件中看到了以下内容,缩写为仅显示我想要的 Artifact 。
compileClasspath - Compile classpath for source set 'main'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)
default - Configuration for default artifacts.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)
+--- com.myco.security:security-service-client:1.0.148 (*)
implementation - Implementation only dependencies for source set 'main'. (n)
+--- com.myco.security:security-service-client:1.0.199 (n)
+--- com.myco.security:security-service-client:1.0.148 (n)
runtimeClasspath - Runtime classpath of source set 'main'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
testCompileClasspath - Compile classpath for source set 'test'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)

IOW,我的 build.gradle文件中的依赖项出现了多次。现在,如果我在原始链接的帖子中应用答案,我将得到
com.myco.security:security-service-client:1.0.199
com.myco.security:security-service-client:1.0.148

作为 Artifact ,而不是以下内容,这就是我要匹配 build.gradle文件中的依赖项的内容。
com.myco.security:security-service-client:1.0.199

如何改善链接帖子中的 awk命令? OW
cat deps.txt | awk '/^\+.*com\.myco/ && !seen[$2]++{print $2}' | some_other_cmd

应该只给我
com.myco.security:security-service-client:1.0.199

最佳答案

您可以使用以下awk:

awk -F '[: ]+' -v OFS=: '/^\+.*com\.myco/ && !seen[$2,$3]++{print $2, $3, $4}' deps.txt
com.myco.security:security-service-client:1.0.199

详细信息:
  • 使用-F '[: ]+'我们在空格或冒号
  • 上拆分列
  • 使用-v OFS=:,我们使用冒号作为输出文件分隔符
  • seen[$2,$3]使用依赖项的group:module作为数组键
  • print $2, $3, $4打印group:module:version
  • 关于bash - 如何过滤掉./gradle project:dependencies命令的特定部分? (版本2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59291987/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com