Fabric API

Fabric API

106M Downloads

Using Guice fails to start up server

yentheo opened this issue ยท 6 comments

commented

So I had a working mod and I was cleaning up my code so I added Guice and its dependencies to my build gradle.

	compile group: 'com.google.inject', name: 'guice', version: '4.2.3'
	compile group: 'org.ow2.asm', name: 'asm', version: '7.2'
	compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
	compile group: 'cglib', name: 'cglib', version: '3.3.0'
	compile group: 'javax.inject', name: 'javax.inject', version: '1'

	compile group: 'com.google.guava', name: 'guava', version: '27.1-jre'
	compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
	compile group: 'com.google.errorprone', name: 'error_prone_annotations', version: '2.2.0'
	compile group: 'com.google.guava', name: 'failureaccess', version: '1.0.1'
	compile group: 'com.google.guava', name: 'listenablefuture', version: '9999.0-empty-to-avoid-conflict-with-guava'
	compile group: 'com.google.j2objc', name: 'j2objc-annotations', version: '1.1'
	compile group: 'org.checkerframework', name: 'checker-qual', version: '2.5.2'
	compile group: 'org.codehaus.mojo', name: 'animal-sniffer-annotations', version: '1.17'

When I debug my mod, it works great. But when I do a gradlew build and copy all jars in the mod folder and run a clean server, it gives an error on java.lang.ClassNotFoundException: com.google.inject.AbstractModule

Full stack trace and server log:

[16:49:31] [main/INFO]: Loading for game Minecraft 20w18a
[16:49:35] [main/INFO]: [FabricLoader] Loading 47 mods: [email protected]+12a8474ce8, [email protected], [email protected]+b50ffc7be8, [email protected]+dfdb52d6e8, [email protected]+fcb6b9aae8, [email protected]+build.194, [email protected], [email protected], [email protected], [email protected]+fa840743e8, [email protected]+6c0e72dfe8, [email protected]+d249f7b6e8, [email protected]+bf7c167ae8, [email protected]+686e6e57e8, [email protected]+2fd224cae8, [email protected]+04b99794e8, [email protected]+b7f9825de8, [email protected], [email protected]+12a8474ce8, [email protected]+53410490e8, [email protected]+304e48ebe8, [email protected]+b7f9825de8, [email protected]+2fd224cae8, [email protected]+821cdba7e8, [email protected]+88afe607e8, [email protected]+2fd224cae8, [email protected]+12a8474ce8, [email protected], [email protected]+686e6e57e8, [email protected]+52d30836e8, [email protected], [email protected]+c6a8ea89e8, [email protected], [email protected]+b764ce99e8, [email protected], [email protected]+5a0f9a60e8, [email protected]+2f56dff2e8, [email protected]+1a47cd78e8, [email protected], [email protected]+build.340-1.16, [email protected], [email protected]+12a8474ce8, [email protected]+dfdb52d6e8, [email protected]+63435d4be8, [email protected]+bf7c167ae8, [email protected]+1a47cd78e8, [email protected]
[16:49:35] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.8 Source=file:/E:/minecraft/backup-corona-20200510/minecraft_server.jar Service=Knot/Fabric Env=SERVER
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[16:49:39] [main/ERROR]: Unable to bootstrap registry 'minecraft:chunk_generator_type'
[16:49:39] [main/ERROR]: Registry 'minecraft:chunk_generator_type' was empty after loading
[16:49:39] [main/INFO]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', name='PROD'
[16:49:39] [main/INFO]: [fabric-registry-sync] Loaded registry data [file 1/4]
[16:49:39] [main/INFO]: [fabric-registry-sync] Loaded registry data [file 1/4]
[16:49:40] [main/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, dd12be42-52a9-4a91-a8a1-11c01849e498]
[16:49:40] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:49:40] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:49:40] [main/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, dd12be42-52a9-4a91-a8a1-11c01849e498]
[16:49:40] [main/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0]
[16:49:40] [main/FATAL]: Failed to start the minecraft server
java.lang.RuntimeException: Could not execute entrypoint stage 'main' due to errors, provided by 'spectra-restream'!
        at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke0(EntrypointUtils.java:53) ~[minecraft_server.jar:?]
        at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke(EntrypointUtils.java:36) ~[minecraft_server.jar:?]
        at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointServer.start(EntrypointServer.java:32) ~[minecraft_server.jar:?]
        at net.minecraft.class_3176.<init>(class_3176.java:94) ~[intermediary-server.jar:?]
        at net.minecraft.server.MinecraftServer.main(MinecraftServer.java:1007) [intermediary-server.jar:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
        at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:192) [minecraft_server.jar:?]
        at net.fabricmc.loader.launch.knot.Knot.init(Knot.java:140) [minecraft_server.jar:?]
        at net.fabricmc.loader.launch.knot.KnotServer.main(KnotServer.java:26) [minecraft_server.jar:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
        at net.fabricmc.loader.launch.server.FabricServerLauncher.launch(FabricServerLauncher.java:61) [minecraft_server.jar:?]
        at net.fabricmc.loader.launch.server.FabricServerLauncher.setup(FabricServerLauncher.java:105) [minecraft_server.jar:?]
        at net.fabricmc.loader.launch.server.FabricServerLauncher.main(FabricServerLauncher.java:49) [minecraft_server.jar:?]
Caused by: java.lang.NoClassDefFoundError: com/google/inject/AbstractModule
        at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_151]
        at java.lang.ClassLoader.defineClass(Unknown Source) ~[?:1.8.0_151]
        at java.security.SecureClassLoader.defineClass(Unknown Source) ~[?:1.8.0_151]
        at net.fabricmc.loader.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:156) ~[minecraft_server.jar:?]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_151]
        at one.spectra.minecraft.restream.RestreamMod.onInitialize(RestreamMod.java:19) ~[spectra-restream-0.0.0.jar:?]
        at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke0(EntrypointUtils.java:50) ~[minecraft_server.jar:?]
        ... 18 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.AbstractModule
        at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_151]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_151]
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[?:1.8.0_151]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_151]
        at net.fabricmc.loader.launch.server.InjectingURLClassLoader.loadClass(InjectingURLClassLoader.java:56) ~[minecraft_server.jar:?]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_151]
        at net.fabricmc.loader.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:161) ~[minecraft_server.jar:?]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_151]
        at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_151]
        at java.lang.ClassLoader.defineClass(Unknown Source) ~[?:1.8.0_151]
        at java.security.SecureClassLoader.defineClass(Unknown Source) ~[?:1.8.0_151]
        at net.fabricmc.loader.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:156) ~[minecraft_server.jar:?]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_151]
        at one.spectra.minecraft.restream.RestreamMod.onInitialize(RestreamMod.java:19) ~[spectra-restream-0.0.0.jar:?]
        at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke0(EntrypointUtils.java:50) ~[minecraft_server.jar:?]
        ... 18 more```

I had similar issues before, but those always got fixed by adding al the maven dependecies of the specific dependency to the build.gradle file. I also added the following step:

task copyToLib(type: Copy) {
into "${buildDir}/libs"
from configurations.runtime
}

build.dependsOn(copyToLib)```
So that when I build, all necessary jars are copied to that libs folder and I can just copy/paste to the mods folder on my server.

There may be better (or even more correct) ways of doing this, so that's why I'm also posting this.

My complete build.gradle file:

plugins {
	id 'fabric-loom' version '0.4.3'
	id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

minecraft {
}

dependencies {
	//to change the versions see the gradle.properties file
	minecraft "com.mojang:minecraft:${project.minecraft_version}"
	mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
	modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

	modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"

	compile "org.java-websocket:Java-WebSocket:1.4.0"

	compile "com.squareup.okhttp3:okhttp:4.4.0"
  	compile 'com.google.code.gson:gson:2.8.6'
	compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
	compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.9'

	compile group: 'com.google.inject', name: 'guice', version: '4.2.3'
	compile group: 'org.ow2.asm', name: 'asm', version: '7.2'
	compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
	compile group: 'cglib', name: 'cglib', version: '3.3.0'
	compile group: 'javax.inject', name: 'javax.inject', version: '1'

	compile group: 'com.google.guava', name: 'guava', version: '27.1-jre'
	compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
	compile group: 'com.google.errorprone', name: 'error_prone_annotations', version: '2.2.0'
	compile group: 'com.google.guava', name: 'failureaccess', version: '1.0.1'
	compile group: 'com.google.guava', name: 'listenablefuture', version: '9999.0-empty-to-avoid-conflict-with-guava'
	compile group: 'com.google.j2objc', name: 'j2objc-annotations', version: '1.1'
	compile group: 'org.checkerframework', name: 'checker-qual', version: '2.5.2'
	compile group: 'org.codehaus.mojo', name: 'animal-sniffer-annotations', version: '1.17'

	include "com.squareup.okhttp3:okhttp:4.4.0"
	include 'com.squareup.okio:okio:2.4.3'
	include 'com.fasterxml.jackson.core:jackson-core:2.9.9'
	include 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
	include 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
	include 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.9'
	include 'org.yaml:snakeyaml:1.26'
	include 'org.java-websocket:Java-WebSocket:1.4.0'
	include "org.jetbrains.kotlin:kotlin-stdlib:1.3.61"
	include "org.slf4j:slf4j-api:1.7.25"
}

processResources {
	inputs.property "version", project.version

	from(sourceSets.main.resources.srcDirs) {
		include "fabric.mod.json"
		expand "version": project.version
	}

	from(sourceSets.main.resources.srcDirs) {
		exclude "fabric.mod.json"
	}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
	options.encoding = "UTF-8"
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
	classifier = "sources"
	from sourceSets.main.allSource
}

jar {
	from "LICENSE"
}

// configure the maven publication
publishing {
	publications {
		mavenJava(MavenPublication) {
			// add all the jars that should be included when publishing to maven
			artifact(jar) {
				builtBy remapJar
			}
			artifact("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar"){
				builtBy remapJar
			}
			artifact(sourcesJar) {
				builtBy remapSourcesJar
			}
		}
	}

	// select the repositories you want to publish to
	repositories {
		// uncomment to publish to the local maven
		// mavenLocal()
	}
}

task copyToLib(type: Copy) {
    into "${buildDir}/libs"
    from configurations.runtime
}

build.dependsOn(copyToLib)```
commented

You have a lot of depencidenies that minecraft already includes thus you should not need to depend on them at all.

Do you really need all of those deps? as I dont think you do.

your crash is happening becuase its unable to find com.google.inject.AbstractModule, Are you including this? its hard to tell as this whole thing is a bit of a mess.

commented

I have a lot of dependencies because I add the dependencies of my direct dependencies too, because otherwise I don't get those jars during my build and loading jars fails at runtime. But the first line of the first snippet I shared contains the depency that should include that class. Which is compile group: 'com.google.inject', name: 'guice', version: '4.2.3'

commented

That seems fine, but you dont seem to include that in your jar.

You also SHOULD NOT be specifying deps that minecraft or fabric already include, such as guava, asm, gson.

Something seems wrong with you having to list out all of those deps in the compile section.

commented

Okay, I'm beginning to understand what I did wrong. So I added 'com.google.inject', name: 'guice', version: '4.2.3' as an include statement too. But when I start the server now I get java.lang.ClassNotFoundException: javax.inject.Provider, which goes away when I add include for that dependency too. But then I get the next one org.aopalliance.intercept.MethodInterceptor. So is it normal that I need to add includes for every dependency my direct dependency is using?

commented

With include you do have to also include the dependencies since it is not transitive.

I've had this experience with configurate before, and I don't know the real solution to it.

commented

Ok thanks @i509VCB and thanks @modmuss50 to take a look at this. My problem was that I did not include so thanks!