Log4j - 如何扫描 Maven 项目中的 log4j 用法以及项目名称?

Log4j - How to scan for log4j usages in maven projects along with project name?

作为Log4jshell问题的一部分,我们正在尝试分析哪些项目使用哪个版本的Log4j。我确实尝试了以下 Maven 命令

mvn dependency:list | grep log4j
mvn dependency:tree -Dverbose
mvn dependency:tree -Dverbose | grep log4

但它只列出这样的信息

mvn dependency:tree | grep log4
[INFO] \- org.apache.logging.log4j:log4j-api:jar:2.13.1:provided
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.13.1:provided
[INFO] |  |  +- log4j:log4j:jar:1.2.16:compile
[INFO] |  |  +- log4j:log4j:jar:1.2.16:compile
[INFO] |  +- log4j:log4j:jar:1.2.17:provided
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.13.1:compile
[INFO] \- org.apache.logging.log4j:log4j-core:jar:2.13.1:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.13.1:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.13.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-log4j2:jar:2.1.8.RELEASE:compile
[INFO] |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.2:compile
[INFO] |  +- org.apache.logging.log4j:log4j-jul:jar:2.11.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-log4j2:jar:2.1.8.RELEASE:compile

我找不到它指向我们工作区中的哪个项目。有人可以帮忙吗?

注意:有几个 Maven 项目,所有 pom.xml 文件都有一个父项目 pom.xml。所以想确定哪些 Maven 项目正在使用 log4j 以及名称。

使用包含选项

 mvn dependency:tree -Dincludes=org.apache.logging.log4j

示例输出:

[INFO] com.test:test:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-security:jar:2.5.3:compile
[INFO]    \- org.springframework.boot:spring-boot-starter:jar:2.5.3:compile
[INFO]       \- org.springframework.boot:spring-boot-starter-logging:jar:2.5.3:compile
[INFO]          \- org.apache.logging.log4j:log4j-to-slf4j:jar:2.14.1:compile
[INFO]             \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile

documentation

感谢您的回答。是的,它确实回答了我的问题。我使用了下面的命令并得到了结果。

mvn dependency:tree -Dincludes=org.apache.logging.log4j -DoutputFile=`pwd`/maven-report-log4j.txt -DappendOutput=true