关于 mvn dependency:analyze Unused declared dependencies found 问题

Posted

技术标签:

【中文标题】关于 mvn dependency:analyze Unused declared dependencies found 问题【英文标题】:About mvn dependency:analyze Unused declared dependencies found problem 【发布时间】:2019-09-24 16:15:14 【问题描述】:

我运行mvn dependency:analyze命令检查我的java项目中未使用的jar,部分结果如下:

[WARNING] 发现未使用的已声明依赖项:[WARNING] org.springframework.boot:spring-boot-starter:jar:2.0.3.RELEASE:comp [警告] org.springframework.boot:spring-boot-starter-test:jar:2.0.3.RELEASE :compile [警告] org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.3.RELEASE :compile [警告] org.springframework.boot:spring-boot-starter-actuator:jar:2.0.3.REL 轻松:编译 [警告] org.aspectj:aspectjweaver:jar:1.8.9:compile [警告]

但是spring-boot-starter-test其实是用在src/test/java包里的,

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class TestClass 
...

我想知道为什么 spring-boot-starter-test: 会出现在 Unused declared dependencies found 部分。 有没有办法找到我的java项目中没有使用的确切jar

【问题讨论】:

【参考方案1】:

如果您声明的依赖项没有<scope> 标签,则将使用<scope>compile</scope>。 如果仅用于测试,则应将其声明为<scope>test</scope>

【讨论】:

嗨 dan1st:我试过 compiletest,它仍然出现在未使用的声明依赖项中,并且在单元测试类旁边,其他一些jar如spring-boot-starter-jdbc也有这个问题 部分文本片段粘贴如下: org.springframework.bootspring-boot-starter-test$ springboot.versioncompileorg.springframework.bootspring-boot- starter-jdbc$springboot.version 删除依赖会怎样? 代码中有引用,eclipse显示编译错误 引用是否只在src/main/java(或测试目录)?

以上是关于关于 mvn dependency:analyze Unused declared dependencies found 问题的主要内容,如果未能解决你的问题,请参考以下文章

maven依赖信息获取

idea配置jetty服务器,通过mvn实现

mvn常见参数命令讲解

mvn build failures:编译失败

MAVEN_HOME、MVN_HOME 或 M2_HOME [重复]

关于“环境变量未定义”的问题