I have a project written in Kotlin called "2D-Game-Engine". The directly structure is as such:
- build.gradle
- src
- main
- test
Here's the full build.gradle file:
buildscript {
ext.kotlinVersion = '1.8.10'
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
}
group = 'com.github.JohnLavender474'
version = '1.0.0'
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
ext {
appName = "2D-Game-Engine"
gdxVersion = '1.11.0'
roboVMVersion = '2.3.16'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.4'
aiVersion = '1.8.2'
gdxControllersVersion = '2.2.1'
}
sourceSets.main.java.srcDirs = [ "src/main/" ]
sourceSets.test.java.srcDirs = [ "src/test/" ]
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
api "com.badlogicgames.gdx:gdx-freetype:1.11.0"
api "com.badlogicgames.gdx:gdx-tools:1.6.3"
api "com.badlogicgames.gdx-controllers:gdx-controllers-core:$gdxControllersVersion"
api "com.badlogicgames.gdx-controllers:gdx-controllers-desktop:$gdxControllersVersion"
testImplementation "com.badlogicgames.gdx:gdx:$gdxVersion"
testImplementation "io.kotest:kotest-runner-junit5-jvm:4.6.0"
testImplementation "io.kotest:kotest-runner-junit5:4.0.2"
testImplementation "io.kotest:kotest-assertions-core:4.0.2"
testImplementation "io.kotest:kotest-property:4.0.2"
testImplementation "io.mockk:mockk:1.13.7"
}
I've tagged a commit as '1.0' and pushed it to Github. Jitpack completes the build successfully:
Build starting...
Start: Sat Feb 10 18:56:49 UTC 2024 def14a800cd4
Git:
1.0-0-ge4140d8
commit e4140d8edc42dd1f4d04d13a012a6b4f92238708
Author: JohnLavender474
Date: Sat Feb 10 13:52:45 2024 -0500
Change project name in build.gradle
Init SDKMan
Found gradle
Gradle build script
Found gradle version: 7.5.1.
Using gradle wrapper
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Downloading https://services.gradle.org/distributions/gradle-7.5.1-bin.zip
.10%.20%.30%.40%.50%.60%.70%.80%.90%.100%
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 1.8.0_252 (Private Build 25.252-b09)
OS: Linux 4.10.0-28-generic amd64
0m3.148s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~16.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Getting tasks: ./gradlew tasks --all
Tasks:
Found javadoc task
⚠️ WARNING:
Gradle 'publishToMavenLocal' task not found. Please add the 'maven-publish' or 'maven' plugin.
See the documentation and examples: https://docs.jitpack.io
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
/home/jitpack/build/build.gradle has component: java
Running: ./gradlew clean -Pgroup=com.github.JohnLavender474 -Pversion=1.0 -xtest publishToMavenLocal
> Task :clean UP-TO-DATE
> Task :processResources NO-SOURCE
> Task :generatePomFileFor2D-Game-EnginePublication
> Task :compileKotlin
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:13:54 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:123:22 'Array2DIterator<T>' is deprecated. Use Matrix instead.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:205:39 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:206:29 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:256:29 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:257:30 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:273:27 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:274:30 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:290:17 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/common/objects/Array2D.kt:453:23 'Array2D<T>' is deprecated. Should use Matrix instead. By default, Matrix iterates from bottom to top. This is almost always the desired behavior.
w: file:///home/jitpack/build/src/main/com/engine/world/WorldGraph.kt:29:30 'WorldGraph' is deprecated. Use instances of IGraphMap instead
w: file:///home/jitpack/build/src/main/com/engine/world/WorldGraph.kt:53:39 'WorldGraph' is deprecated. Use instances of IGraphMap instead
w: file:///home/jitpack/build/src/main/com/engine/world/WorldGraph.kt:71:53 'WorldGraph' is deprecated. Use instances of IGraphMap instead
> Task :compileJava
> Task :classes
> Task :jar
> Task :inspectClassesForKotlinIC
> Task :assemble
> Task :generateMetadataFileFor2D-Game-EnginePublication
> Task :publish2D-Game-EnginePublicationToMavenLocal
> Task :publishToMavenLocal
BUILD SUCCESSFUL in 23s
8 actionable tasks: 7 executed, 1 up-to-date
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Archive: com.github.JohnLavender474:2D-Game-Engine:1.0.0
Publication: com.github.JohnLavender474:2D-Game-Engine:1.0.0
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
Found artifact: com.github.JohnLavender474:2D-Game-Engine:1.0.0
Found artifact: com.github.JohnLavender474:2D-Game-Engine:1.0.0
2024-02-10T18:57:36.712055127Z
Exit code: 0
✅ Build artifacts:
com.github.JohnLavender474:2D-Game-Engine:1.0
Files:
com/github/JohnLavender474/2D-Game-Engine/1.0
com/github/JohnLavender474/2D-Game-Engine/1.0/2D-Game-Engine-1.0.jar
com/github/JohnLavender474/2D-Game-Engine/1.0/2D-Game-Engine-1.0.module
com/github/JohnLavender474/2D-Game-Engine/1.0/2D-Game-Engine-1.0.pom
com/github/JohnLavender474/2D-Game-Engine/1.0/2D-Game-Engine-1.0.pom.md5
com/github/JohnLavender474/2D-Game-Engine/1.0/2D-Game-Engine-1.0.pom.sha1
com/github/JohnLavender474/2D-Game-Engine/1.0/build.log
Now I'm wanting to pull this project as a dependency into another project I have called "Megaman Maverick" which is built using LibGDX. The project structure is as such:
- build.gradle
- core [module]
- src
- test
- desktop [module]
Here's the build.gradle file for "Megaman Maverick":
buildscript {
ext.kotlinVersion = '1.8.10'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url 'https://jitpack.io' }
google()
}
}
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "Megaman Maverick"
gdxVersion = '1.12.1'
roboVMVersion = '2.3.16'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.4'
aiVersion = '1.8.2'
gdxControllersVersion = '2.2.1'
}
repositories {
mavenLocal()
mavenCentral()
google()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
maven { url "https://jitpack.io" }
}
}
project(":desktop") {
apply plugin: "kotlin"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx-controllers:gdx-controllers-desktop:$gdxControllersVersion"
api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
}
project(":core") {
apply plugin: "kotlin"
apply plugin: "java-library"
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx-controllers:gdx-controllers-core:$gdxControllersVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
/* api fileTree(dir: 'libs', include: '*.jar') */
implementation "com.github.JohnLavender474:2D-Game-Engine:1.0"
testImplementation "com.badlogicgames.gdx:gdx:$gdxVersion"
testImplementation "io.kotest:kotest-runner-junit5-jvm:4.6.0"
testImplementation "io.kotest:kotest-runner-junit5:4.0.2"
testImplementation "io.kotest:kotest-assertions-core:4.0.2"
testImplementation "io.kotest:kotest-property:4.0.2"
testImplementation "io.mockk:mockk:1.13.7"
}
}
Inside the "desktop" module is the following runner class:
package com.megaman.maverick.game;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowAdapter;
// Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument
public class DesktopLauncher {
private static final int FPS = 60;
private static final int WIDTH = 1920;
private static final int HEIGHT = 1080;
private static final boolean VSYNC = false;
private static final String TITLE = "Megaman Maverick";
public static void main(String[] arg) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setTitle(TITLE);
config.useVsync(VSYNC);
config.setIdleFPS(FPS);
config.setForegroundFPS(FPS);
config.setWindowedMode(WIDTH, HEIGHT);
Game game = new MegamanMaverickGame();
config.setWindowListener(new Lwjgl3WindowAdapter() {
@Override
public void iconified(boolean isIconified) {
game.pause();
}
@Override
public void focusGained() {
game.resume();
}
@Override
public void focusLost() {
game.pause();
}
});
new Lwjgl3Application(game, config);
}
}
However, when I try building the project, I get the following error:
2:29:45 PM: Executing 'build'...
> Task :core:compileKotlin UP-TO-DATE
> Task :core:compileJava UP-TO-DATE
> Task :core:processResources NO-SOURCE
> Task :core:classes UP-TO-DATE
> Task :core:jar UP-TO-DATE
> Task :core:inspectClassesForKotlinIC UP-TO-DATE
> Task :core:assemble UP-TO-DATE
> Task :core:compileTestKotlin UP-TO-DATE
> Task :core:compileTestJava NO-SOURCE
> Task :core:processTestResources NO-SOURCE
> Task :core:testClasses UP-TO-DATE
> Task :core:test UP-TO-DATE
> Task :core:check UP-TO-DATE
> Task :core:build UP-TO-DATE
> Task :desktop:compileKotlin NO-SOURCE
> Task :desktop:compileJava FAILED
/home/johnlavender/IdeaProjects/Megaman-Maverick/desktop/src/com/megaman/maverick/game/DesktopLauncher.java:24: error: cannot access Game2D
Game game = new MegamanMaverickGame();
^
class file for com.engine.Game2D not found
1 error
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':desktop:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
BUILD FAILED in 399ms
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings
7 actionable tasks: 1 executed, 6 up-to-date
2:29:46 PM: Execution finished 'build'.
The Game2D is a public class in the 2D-Game-Engine project. I've tried deleting the gradle cache and rebuilding from scratch but nothing seems to work.
Any help would be greatly appreciated. For full context, here's the repos:
I've managed to fix the issue by including the "2D-Game-Engine" as a dependency for both the "core" and "desktop" modules. I'd assumed that since "core" is listed as a dependency for "desktop" that this wouldn't be necessary, but adding it twice seems to resolve the issue.