[英]How to find if I need to exclude dependencies in a maven java project?
I use both Intellij IDEA (2018.3.5) & Eclipse IDEs, but I prefer Intellij.我同时使用 Intellij IDEA (2018.3.5) 和 Eclipse IDE,但我更喜欢 Intellij。 I have a maven based Java project with multiple poms.
我有一个基于 maven 的 Java 项目,其中包含多个 poms。 I added some dependencies to one of the pom files.
我向其中一个 pom 文件添加了一些依赖项。 I need to find out if there are any dependency conflicts which could prevent the build from running when its deployed, and then exclude them.
我需要找出是否有任何依赖冲突会阻止构建在部署时运行,然后排除它们。 I tried the steps given below to find conflicts which could cause problems.
我尝试了下面给出的步骤来查找可能导致问题的冲突。 Are they enough or do I need to do more ?
它们足够了吗,还是我需要做更多?
Check if there are any compile time dependency conflicts with mvn clean install -DskipTests
.检查是否与
mvn clean install -DskipTests
存在任何编译时依赖冲突。 Build was successful with no errors.构建成功,没有错误。
Check if Intellij shows no problems under File > Project Structure > Problems.检查 Intellij 在文件 > 项目结构 > 问题下是否显示没有问题。 There are no problems.
没有问题。
I also saw the dependency tree with mvn dependency:tree -Dverbose
.我还看到了
mvn dependency:tree -Dverbose
。 It has a lot of "omitted for duplicate" and "omitted for conflict with" items, but the build was successful.它有很多“因重复而省略”和“因冲突而省略”的项目,但构建成功。 I don't see any errors though.
虽然我没有看到任何错误。 Does this mean that everything is okay or do I have to do something more about these conflicts ?
这是否意味着一切正常,还是我必须对这些冲突做更多的事情?
The best way to tell if everything is fine with your application is to have good tests.判断您的应用程序是否一切正常的最佳方法是进行良好的测试。
However normally one doesn't exclude transitive dependencies from project's <dependency>
libraries.然而,通常不会从项目的
<dependency>
库中排除传递依赖项。 Doing it can potentially break the dependency in a subtle and hard to notice way.这样做可能会以一种微妙且难以察觉的方式打破依赖关系。 It's usually safer to remove the whole
<dependency>
.删除整个
<dependency>
通常更安全。
There are few scenario when one should use <exclude>
:应该使用
<exclude>
情况很少:
Dealing with incompatible transitive dependencies between different libraries eg A requires library C-1.0 but library B requires library C-2.0 while C-1.0 and C-2.0 can't coexist on the classpath.处理不同库之间不兼容的传递依赖关系,例如 A 需要库 C-1.0,而库 B 需要库 C-2.0,而 C-1.0 和 C-2.0 不能在类路径上共存。
Having transitive dependencies already provided by system eg deploying to Tomcat with additional JARs in the TOMCAT_HOME/lib
directory.具有系统已经提供的传递依赖项,例如部署到 Tomcat 和
TOMCAT_HOME/lib
目录中的附加 JAR。
If you decide to exclude a dependency it's important that you check the final artifact because sometimes plugins do weird things eg there were versions of maven-assembly-plugin
affected by a bug that resulted in different dependencies being resolved during shaded JAR creation than maven-dependency-plugin
used for compilation.如果您决定排除依赖项,请务必检查最终工件,因为有时插件会做一些奇怪的事情,例如,
maven-assembly-plugin
版本受 bug 影响,导致在着色 JAR 创建期间解决不同的依赖项而不是maven-dependency-plugin
用于编译的maven-dependency-plugin
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.