【问题标题】:How to fix dependency resolution errors?如何修复依赖解析错误?
【发布时间】:2020-11-29 15:19:17
【问题描述】:

我正在 libgdx 中开发一个游戏,我正在使用一个外部 jar 来处理 JSON,我知道 libgdx 有它自己的,但我以前使用过这个 jar,我知道如何使用它。无论如何,我将它添加到我的根目录中的 build.gradle 并同步。但是现在当我尝试构建项目时,我收到了这个大错误消息:

Duplicate class org.hamcrest.BaseDescription found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.BaseMatcher found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.CoreMatchers found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.Description found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.Factory found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.Matcher found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.SelfDescribing found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.StringDescription found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.AllOf found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.AnyOf found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.DescribedAs found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.Is found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsAnything found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsEqual found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsInstanceOf found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNot found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNull found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsSame found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.internal.ArrayIterator found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValue found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValueIterator found in modules hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar (junit:junit:4.10)

我不知道这意味着什么,也不知道这个 org.hamcrest 有什么重复项。这是我的 build.gradle 文件:

buildscript {
    

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
        google()
    }
    dependencies {
        classpath 'org.wisepersist:gwt-gradle-plugin:1.0.9'
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.8'
        

    }
}

allprojects {
    apply plugin: "eclipse"

    version = '1.0'
    ext {
        appName = "ShootOut"
        gdxVersion = '1.9.10'
        roboVMVersion = '2.3.8'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        google()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java-library"


    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
        
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
        api "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-x86_64"
        api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
        api "com.badlogicgames.ashley:ashley:$ashleyVersion"
        api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
        api "com.badlogicgames.gdx:gdx-ai:$aiVersion"
        api "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-controllers-android:$gdxVersion"
        
    }
}

project(":ios") {
    apply plugin: "java-library"
    apply plugin: "robovm"


    dependencies {
        implementation project(":core")
        api "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
        api "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
        api "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
        api "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-ios"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
        
    }
}

project(":html") {
    apply plugin: "java-library"
    apply plugin: "gwt"
    apply plugin: "war"


    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
        api "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
        api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
        api "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
        api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion:sources"
        api "com.badlogicgames.ashley:ashley:$ashleyVersion:sources"
        api "com.badlogicgames.gdx:gdx-ai:$aiVersion:sources"
        api "com.badlogicgames.gdx:gdx-controllers:$gdxVersion:sources"
        api "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion:sources"
        
    }
}

project(":core") {
    apply plugin: "java-library"


    dependencies {
        implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
        api "com.badlogicgames.gdx:gdx:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
        api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
        api "com.badlogicgames.ashley:ashley:$ashleyVersion"
        api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-ai:$aiVersion"
        api "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
        
    }
}

我唯一添加的是“实现组:'com.googlecode.json-simple',名称:'json-simple',版本:'1.1.1'”到我核心项目的依赖项中。 知道如何解决此错误吗?或者是什么原因造成的?

【问题讨论】:

  • 您的一个库包含JUnit(可能是junit-dep,其中包含hamcrest-core。另一个库也包含hamcrest-core 的某个位置。
  • 解决了吗?
  • @IntelliJAmiya 是的!我最终排除了 JUnit

标签: java android android-studio libgdx dependency-resolution


【解决方案1】:

我最终不得不添加:

configurations { compile.exclude group: "junit", module: "junit"}

在 build.gradle 的核心部分,它起作用了。

【讨论】:

    【解决方案2】:

    尝试将以下行添加到应用程序build.gradle 文件中。

    android {
        // Some other stuffs
        configurations {
            all*.exclude module: 'org.hamcrest' // This removes all other versions of `org.hamcrest` if gets duplicated from all the artifacts.
        }
        // other stuffs
    }
    

    【讨论】:

    • 我最终不得不添加 :configurations { compile.exclude group: "junit", module: "junit"},但是它起作用了,但我仍然对它为什么没有运行感到困惑之前遇到过这个问题吗?由于我添加的 jar 不包含重复项。
    猜你喜欢
    • 2021-10-16
    • 2014-11-12
    • 2022-01-21
    • 2018-08-17
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多