I've got a small multi-project setup with gradle (also new to it), but it doesn't compile. I can run it inside of the IDE, but when I want to compile it, it fails. When I then try to use one of the dependencies from the Engine project in the Game project it even fails inside of the IDE. More details further down.
: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
My file hirachy is quite simple:
Project\Engine
Project\Game
My Game project should use the Engine project, so that I can easily change things in the Engine project without having to build a new .jar file for it and the Game project just works with it (like if you would for example add it as a dependency project in eclipse) and when compiling the Game project it should compile the Engine project to get the required jar for the Game project.
Currently it works the way that the Game project has it's dependencies on the Engine project and this works quite nice in my IDE (well, atleast when the Engine project is importet), but as soon as I run the build it fails as the error shows above. It also fails in the IDE when I want to have access to a class which is a dependency in the Engine project, but not in the Game project where the complete Engine project is the dependency.
The build.gradle file of the Game project.
// 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')
}
The settings.gradle file of the Game project:
include 'Engine'
project (':Engine').projectDir = new File('../Engine')
rootProject.name = 'Game'
Then I've got here the build.gradle file of the Engine project:
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
}
So why am I getting this error and how can I solve it in a way that I can run and build is project on Linux, Windows and Mac with the IDEs Eclipse and Intellij? The error occurs only when running
gradlew build
inside the Game project. Building the engine project works just fine. It works also fine when I run the Game project inside of for example eclipse, but when I want to build it or want to use a class to which the Engine project has access in the Game project, it fails.
EDIT (Better answer)
I would organize projects differently.
Try to use this hierarchy :
Project/
|
+- Game/
+- Engine/
+- build.gradle
+- settings.gradle
In your settings.gradle
include ':Game'
include ':Engine'
In your build.gradle of project root
// 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
node of your child projects are not needed anymore.
settings.gradle of your game project is just
rootProject.name = 'Game'