我正在使用 Dropwizard 和 Titan DB 开发一个项目。两者都依赖于 Google Guava。一个依赖15版本,一个依赖18版本,运行时出现这个错误:
! java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool$ID
BlockRunnable
我研究了这个错误并 found它是由泰坦的 Guava 引起的 15.0 依赖被 Guava 18.0 驱逐。
我是 Java 和 Gradle 的新手。我正在使用 Gradle 的 java
和 application
插件通过 gradle run
构建和运行主类。我该如何解决这个问题?
这是我的build.gradle
:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "com.example.rest.App"
repositories {
mavenCentral()
}
dependencies {
compile (
[group: 'io.dropwizard', name: 'dropwizard-core', version: '0.8.0-rc1'],
[group: 'com.thinkaurelius.titan', name: 'titan-core', version: '0.5.1'],
[group: 'com.thinkaurelius.titan', name: 'titan-berkeleyje', version: '0.5.1'],
[group: 'com.tinkerpop', name: 'frames', version: '2.6.0']
)
testCompile group: 'junit', name: 'junit', version: '3.8.1'
}
run {
if ( project.hasProperty("appArgs") ) {
args Eval.me(appArgs)
}
}
最佳答案
默认情况下,Gradle 会在发生冲突时为依赖项选择最高版本。您可以强制将特定版本与自定义 resolutionStrategy 一起使用(改编自 http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html ):
configurations.all {
resolutionStrategy {
force 'com.google.guava:guava:15.0'
}
}
这不会添加对 guava 15.0 的依赖,但会说明是否存在强制使用 15.0 的依赖(甚至可传递)。
您可以通过 gradle dependencies
和 gradle dependencyInsight ...
获取有关依赖项来源的更多信息。
仅供引用,您似乎请求了几个不同版本的 Guava(11.0.2、14.0.1、15.0 和 18.0)。
HTH
关于java - 如何解决与 Gradle 的依赖冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27004899/