在我的项目中,jersey-core 来自许多依赖项。我不知道来自哪些。我相信这并不重要,因为我认为如果多个依赖项拉同一个依赖项,那么 gradle 总是会采用更高的版本。我错了。
[ERROR] [main] [n/a] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - StandardWrapper.Throwable
java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;
at com.sun.jersey.spi.scanning.AnnotationScannerListener.<init>(AnnotationScannerListener.java:94) ~[jersey-server-1.19.jar:1.19]
AnnotationScannerListener为1.19,ReflectionHelper为1.1,ReflectionHelper 1.1中不存在getContextClassLoaderPA()方法
如何强制 gradle 始终采用较高版本?
我使用intellij。
最佳答案
默认情况下,gradle 应该将最高版本的依赖项添加到类路径中。
您可以强制依赖项的版本为特定版本,如下所示:
configurations.all {
resolutionStrategy {
// force certain versions of dependencies (including transitive)
// *append new forced modules:
force 'asm:asm-all:3.3.1', 'commons-io:commons-io:1.4'
}
}
这个例子直接取自 https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html ,这可能值得一读,以及 https://docs.gradle.org/current/userguide/dependency_management.html
另一条建议,如果您想找出冲突版本的 jar 中存在哪些问题,您可以执行以下操作:
gradle dependencyInsight --dependency $dependencyName --configuration $configurationName
其中 $dependencyName
应替换为依赖项的名称(例如 asm-all
),并且应替换 $configurationName
带有您要检查的配置名称(例如 compile
)。这将为您提供一个图表,显示哪些依赖项正在拉入哪些版本。
关于java - Gradle拉取依赖时版本冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38590032/