具有依赖性的Gradle多项目设置 - >无法解决所有依赖关系

时间:2016-10-16 23:56:10

标签: java eclipse intellij-idea gradle gradlew

我有一个带有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

我的文件hirachy非常简单:

  

Project \ Engine

     

项目\游戏

My Game项目应该使用Engine项目,这样我就可以轻松更改Engine项目中的内容,而无需为它构建新的.jar文件。 Game项目只是适用它(比如你可以在eclipse中将它添加为依赖项目),在编译Game项目时,它应该编译Engine项目以获得Game项目所需的jar。

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

Game项目的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
}

那么为什么我会收到这个错误?我怎样才能解决这个错误,我可以运行和构建项目是Linux,Windows和Mac上的IDE和Eclipse和Intellij? 仅在运行

时才会发生错误
  

gradlew build

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

1 个答案:

答案 0 :(得分: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'
相关问题