【问题标题】:About mvn dependency:analyze Unused declared dependencies found problem关于 mvn dependency:analyze Unused declared dependencies found 问题
【发布时间】: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

【问题讨论】:

    标签: maven


    【解决方案1】:

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

    【讨论】:

    • 嗨 dan1st:我试过 compiletest,它仍然出现在未使用的声明依赖项中,并且在单元测试类旁边,其他一些jar如spring-boot-starter-jdbc也有这个问题
    • 部分文本片段粘贴如下: org.springframework.bootspring-boot-starter-test$ {springboot.version}compileorg.springframework.bootspring-boot- starter-jdbc${springboot.version}
    • 删除依赖会怎样?
    • 代码中有引用,eclipse显示编译错误
    • 引用是否只在src/main/java(或测试目录)?
    猜你喜欢
    • 2018-06-30
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 2022-06-10
    • 2012-01-15
    • 2020-10-04
    • 2010-12-09
    相关资源
    最近更新 更多