[英]Gradle Multi-Project Setup with Dependencies -> Could not resolve all dependencies
我有一个带有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
我的文件记录很简单:
项目\\引擎
项目\\游戏
我的Game项目应该使用Engine项目,这样我就可以轻松地更改Engine项目中的内容,而不必为其构建新的.jar文件,而Game项目也可以使用它(例如,如果您将其添加为Eclipse中的依赖项目),并且在编译Game项目时,应该编译Engine项目以获取Game项目所需的jar。
目前,它的工作方式是Game项目依赖于Engine项目,并且在我的IDE中工作得很好(嗯,至少在引擎项目为importet时有效),但是一旦运行构建,它就会因错误显示而失败以上。 当我想访问一个类,该类在Engine项目中是一个依赖项,但在完整的Engine项目是依赖项的Game项目中却不能访问时,它在IDE中也会失败。
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上使用Eclipse和Intellij IDE进行的? 仅在运行时发生错误
gradlew构建
在游戏项目中。 构建引擎项目工作正常。 当我在Eclipse中运行Game项目时,它也可以正常工作,但是当我要构建它或要使用Game项目中Engine项目可以访问的类时,它就会失败。
编辑(更好的答案)
我会以不同的方式组织项目。
尝试使用此层次结构:
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.