【问题标题】:Simple way to remove unused dependencies from POM in Spring Initializr web project (IntelliJ Idea 2017.2.1)在 Spring Initializr Web 项目中从 POM 中删除未使用依赖项的简单方法(IntelliJ Idea 2017.2.1)
【发布时间】:2018-01-23 12:24:09
【问题描述】:

我在 Intellij Idea 中创建了一个简单的 Spring Initializr Web 项目。创建项目后,我在pom.xml 文件中只看到两个依赖项(spring-boot-starter-webspring-boot-starter-test),但项目结构中的External Libraries 确实包含许多未使用的jar(这显然会降低性能)。请参阅下面的屏幕截图。

是否有任何快捷方式或手动方式来删除未使用的依赖项并仅保留所需的依赖项?

编辑

虽然Remove Unused Resources 选项可用(右键单击External Libraries 然后Refactor 选项)但它似乎不起作用。

【问题讨论】:

  • 你为什么关心这个?这些很可能是 maven 插件、spring boot web 和测试依赖项所需的传递依赖项。此外,当找不到所需的类时,删除您认为不需要的依赖项将导致运行时异常。 Spring 管理依赖项

标签: maven spring-boot intellij-idea pom.xml


【解决方案1】:

你可以试试dependency:analyze,它会对你有所帮助。 dependency:analyze 的主要目标是分析项目中的依赖关系并确定哪些是used and declaredused and undeclaredunused and declared

您也可以参考以下链接进行更多研究:

http://maven.apache.org/plugins/maven-dependency-plugin/index.html http://maven.apache.org/plugins/maven-dependency-plugin/usage.html

您可以尝试运行mvn dependency:tree,这不会删除依赖项
但它允许您自己进行分析

【讨论】:

  • 感谢玛扬克!!!在挖掘我的问题的解决方案时,我在 StackOverflow 本身上遇到了这个问题。这肯定会分析 eclipse Maven 项目中的依赖问题,但不幸的是 IntelliJ 中没有。无论如何,我会尝试你提到的最后一个命令,让我们看看。
  • 我在项目根目录下运行了命令,可惜好像没有变化。
  • mvn dependency:tree 只创建依赖冲突,找出Commons Collections 的原因。更多请参考maven.apache.org/plugins/maven-dependency-plugin/examples/…。找到后可以手动删除依赖。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-29
  • 2018-05-10
  • 2015-05-22
  • 1970-01-01
  • 2017-02-14
相关资源
最近更新 更多