【问题标题】:Gradle Multi-Project Setup with Dependencies -> Could not resolve all dependenciesGradle Multi-Project Setup with Dependencies -> 无法解析所有依赖项
【发布时间】:2017-02-25 20:53:06
【问题描述】:

我有一个带有 gradle 的小型多项目设置(也是新的),但它无法编译。 我可以在 IDE 中运行它,但是当我想编译它时,它会失败。 然后,当我尝试在 Game 项目中使用 Engine 项目的依赖项之一时,它甚至在 IDE 内部都失败了。 更多细节进一步向下。

:Engine:compileJava UP-TO-DATE
:Engine:processResources UP-TO-DATE
:Engine:classes UP-TO-DATE
:Engine:jar
:compileJava

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not find org.lwjgl:lwjgl:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl/3.0.1-SNAPSHOT/lwjgl-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl/3.0.1-SNAPSHOT/lwjgl-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-egl:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-egl/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-egl/3.0.1-SNAPSHOT/lwjgl-egl-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-egl/3.0.1-SNAPSHOT/lwjgl-egl-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-glfw:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-glfw/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-glfw/3.0.1-SNAPSHOT/lwjgl-glfw-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-glfw/3.0.1-SNAPSHOT/lwjgl-glfw-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-jemalloc:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-jemalloc/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-jemalloc/3.0.1-SNAPSHOT/lwjgl-jemalloc-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-jemalloc/3.0.1-SNAPSHOT/lwjgl-jemalloc-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-openal:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-openal/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-openal/3.0.1-SNAPSHOT/lwjgl-openal-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-openal/3.0.1-SNAPSHOT/lwjgl-openal-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-opencl:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opencl/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opencl/3.0.1-SNAPSHOT/lwjgl-opencl-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opencl/3.0.1-SNAPSHOT/lwjgl-opencl-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-opengl:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opengl/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opengl/3.0.1-SNAPSHOT/lwjgl-opengl-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opengl/3.0.1-SNAPSHOT/lwjgl-opengl-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-opengles:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opengles/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opengles/3.0.1-SNAPSHOT/lwjgl-opengles-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-opengles/3.0.1-SNAPSHOT/lwjgl-opengles-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-stb:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-stb/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-stb/3.0.1-SNAPSHOT/lwjgl-stb-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-stb/3.0.1-SNAPSHOT/lwjgl-stb-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine
> Could not find org.lwjgl:lwjgl-vulkan:3.0.1-SNAPSHOT.
  Searched in the following locations:
      https://jcenter.bintray.com/org/lwjgl/lwjgl-vulkan/3.0.1-SNAPSHOT/maven-metadata.xml
      https://jcenter.bintray.com/org/lwjgl/lwjgl-vulkan/3.0.1-SNAPSHOT/lwjgl-vulkan-3.0.1-SNAPSHOT.pom
      https://jcenter.bintray.com/org/lwjgl/lwjgl-vulkan/3.0.1-SNAPSHOT/lwjgl-vulkan-3.0.1-SNAPSHOT.jar
  Required by:
      project : > project :Engine

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 9.375 secs

我的文件结构很简单:

项目\引擎

项目\游戏

我的游戏项目应该使用 Engine 项目,这样我就可以轻松地更改 Engine 项目中的内容,而无需为其构建新的 .jar 文件并 Game 项目只适用于它(例如,如果您将其添加为 eclipse 中的依赖项项目),并且在编译 Game 项目时,它应该编译 Engine 项目以获取 Game 项目所需的 jar。

目前它的工作方式是 Game 项目依赖于 Engine 项目,这在我的 IDE 中工作得非常好(好吧,至少在 Engine 项目是 importet 时),但是一旦我运行构建它就会失败错误如上所示。 当我想访问一个在引擎项目中是依赖项的类时,它在 IDE 中也会失败,但在完整的引擎项目是依赖项的游戏项目中却没有。

游戏项目的 build.gradle 文件。

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    //compile 'org.slf4j:slf4j-api:1.7.21'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    //testCompile 'junit:junit:4.12'
    
    compile project(':Engine')
    runtime project(':Engine')
}

Game项目的settings.gradle文件:

include 'Engine'
project (':Engine').projectDir = new File('../Engine') 

rootProject.name = 'Game'

然后我得到了 Engine 项目的 build.gradle 文件:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

sourceCompatibility = 1.8
targetCompatibility = 1.8

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.1'
}

sourceSets {
    main.java.srcDir "src/main/java"
}

project.ext.lwjglVersion = "3.0.1-SNAPSHOT"

import org.gradle.internal.os.OperatingSystem

switch ( OperatingSystem.current() ) {
    case OperatingSystem.WINDOWS:
      project.ext.lwjglNatives = "natives-windows"
      break
    case OperatingSystem.LINUX:
      project.ext.lwjglNatives = "natives-linux"
      break
    case OperatingSystem.MAC_OS:
      project.ext.lwjglNatives = "natives-macos"
      break
}

dependencies {
    // LWJGL dependencies START
    compile "org.lwjgl:lwjgl:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-egl:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-glfw:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-jemalloc:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-openal:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-opencl:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-opengl:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-opengles:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-stb:${lwjglVersion}"
    compile "org.lwjgl:lwjgl-vulkan:${lwjglVersion}"
    // LWJGL natives
    runtime "org.lwjgl:lwjgl:${lwjglVersion}:${lwjglNatives}"
    runtime "org.lwjgl:lwjgl-glfw:${lwjglVersion}:${lwjglNatives}"
    runtime "org.lwjgl:lwjgl-jemalloc:${lwjglVersion}:${lwjglNatives}"
    runtime "org.lwjgl:lwjgl-openal:${lwjglVersion}:${lwjglNatives}"
    runtime "org.lwjgl:lwjgl-stb:${lwjglVersion}:${lwjglNatives}"
    // LWJGL dependencies END
}

那么为什么我会收到这个错误,我该如何解决这个问题,我可以使用 IDE Eclipse 和 Intellij 在 Linux、Windows 和 Mac 上运行和构建项目? 错误只在运行时出现

gradlew 构建

在游戏项目中。构建引擎项目工作得很好。当我在例如 eclipse 中运行游戏项目时,它也可以正常工作,但是当我想要构建它或想要使用引擎项目在游戏项目中可以访问的类时,它会失败。

【问题讨论】:

    标签: java eclipse intellij-idea gradle gradlew


    【解决方案1】:

    编辑(更好的答案)

    我会以不同的方式组织项目。

    尝试使用这个层次结构:

    Project/ 
      |
      +- Game/
      +- Engine/
      +- build.gradle
      +- settings.gradle
    

    在你的 settings.gradle 中

    include ':Game'
    include ':Engine'
    

    在项目根目录的 build.gradle 中

    // In this section you declare where to find the dependencies of your project
    repositories {
        // Use 'jcenter' for resolving your dependencies.
        // You can declare any Maven/Ivy/file repository here.
        jcenter()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
    

    您的子项目的repositories 节点不再需要。

    你的游戏项目的settings.gradle只是

    rootProject.name = 'Game'
    

    【讨论】:

    • 是的,JCenter 存储库中没有。这就是为什么我放了一个指向可以找到它们的存储库的链接:
    • 有了指向存储库的链接,它就可以正常工作。 link Engine 项目可以很好地下载这些文件。只是游戏项目似乎有问题下载它们。 (找到它们的存储库链接在 Engine 项目中)
    • 新答案更好吗?
    猜你喜欢
    • 1970-01-01
    • 2020-01-07
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 2015-03-12
    • 2018-03-06
    • 1970-01-01
    相关资源
    最近更新 更多