简体   繁体   English

如何解决与Gradle的依赖冲突?

[英]How do I resolve dependency conflicts with Gradle?

I am developing a project with Dropwizard and Titan DB. 我正在使用Dropwizard和Titan DB开发一个项目。 Both depend on Google Guava. 两者都依赖于谷歌番石榴。 One depends on version 15 and the other on 18. This error occurs at runtime: 一个取决于版本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

I researched the error and found that it was being caused by titan's Guava 15.0 dependency being evicted by Guava 18.0. 我研究了这个错误, 发现它是由泰坦的Guava 15.0依赖被Guava 18.0驱逐引起的。

I am new to Java and Gradle. 我是Java和Gradle的新手。 I am using Gradle's java and application plugins to build and run the main class with gradle run . 我正在使用Gradle的javaapplication插件来构建和运行gradle run的主类。 How can I resolve this problem? 我该如何解决这个问题?


Here is my build.gradle : 这是我的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)  
    }  
}

By default, Gradle will select the highest version for a dependency when there's a conflict. 默认情况下,Gradle将在发生冲突时为依赖项选择最高版本。 You can force a particular version to be used with a custom resolutionStrategy (adapted from http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html ): 您可以强制将特定版本与自定义resolutionStrategy一起使用(改编自http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html ):

configurations.all {
  resolutionStrategy {
    force 'com.google.guava:guava:15.0'
  }
}

This doesn't add a dependency on guava 15.0, but says if there is a dependency (even transitively) to force the use of 15.0. 这并没有增加对番石榴15.0的依赖,但是说如果有依赖(甚至是传递)强制使用15.0。

You can get more information on where your dependencies come from with gradle dependencies and gradle dependencyInsight ... . 您可以通过gradle dependenciesgradle dependencyInsight ...获取有关依赖项来源的更多信息gradle dependencyInsight ...

FYI, it looks like you have a few different versions of Guava requested (11.0.2, 14.0.1, 15.0 and 18.0). 仅供参考,看起来你有几个不同版本的Guava(11.0.2,14.0.1,15.0和18.0)。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM