CoreProtect

CoreProtect

1M Downloads

Can't use self-built jar file on spigot 1.21 server

Plackett opened this issue · 5 comments

commented

image
Trying to build the latest version of this repo to fix an error I previously commented on that was resolved, but whenever I try to build it I get two errors:

  1. I had to switch to java 17 because using java 21 resulted in a java.lang.IllegalArgumentException: Unsupported class file major version 65 when on the :shadowJar task running gradle build.
  2. I get the error shown in the picture, even after changing build.gradle to set projectBranch to development.

Tell me if I missed any important information, tysm.

commented

Use Maven build. I successfully built it.

commented

here is my build.gradle if it helps:

import org.apache.tools.ant.filters.ReplaceTokens

plugins {
    id 'java'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
    id 'com.palantir.git-version' version '0.13.0'
}

group = 'net.coreprotect'
String projectVersion = '22.4'
String projectBranch = "development"
version = projectVersion // `version` might be modified, we don't always want that (e.g. plugin.yml)
description = 'Provides block protection for your server.'
sourceCompatibility = '17'
compileJava.options.fork = true
compileJava.options.forkOptions.executable = 'C:/Program Files/Eclipse Adoptium/jdk-17.0.7.7-hotspot/bin/javac.exe'

if (System.getenv("BUILD_NUMBER") != null) {
    // Being built in Jenkins, append Build ID
    version += "-${System.getenv("BUILD_NUMBER")}"
} else if (!(version ==~ '^[^.]*\\.[^.]*\\.[^.]*$')) { // Thanks https://stackoverflow.com/a/9949200/1709894
    // Append the Git hash if 'version' has less than two periods
    version += "-${gitVersion()}"
}
logger.info("Building version $version")

repositories {
    maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' }
    maven { url = 'https://repo.papermc.io/repository/maven-public/' }
    maven { url = 'https://repo.codemc.org/repository/maven-public/' }
}

dependencies {
    implementation(platform("com.intellectualsites.bom:bom-newest:1.44")) // Ref: https://github.com/IntellectualSites/bom
    compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")
    compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit")
    compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT'
    implementation 'org.bstats:bstats-bukkit-lite:1.8'
    implementation 'com.zaxxer:HikariCP:5.0.1'
}

jar {
    archiveClassifier.set("original")
}

artifacts {
    archives shadowJar
}

shadowJar {
    dependencies {
        // #toString because #getGroup technically returns an Object
        relocate('org.bstats', project.group.toString())
        relocate('com.zaxxer', project.group.toString())
        exclude(dependency('com.google.code.gson:.*'))
        exclude(dependency('org.intellij:.*'))
        exclude(dependency('org.jetbrains:.*'))
        exclude(dependency('org.slf4j:.*'))
    }
    archiveClassifier.set(null)
}

ext {
    author = 'Intelli'

    resourceTokens = [
            'project.version': projectVersion,
            'project.branch': projectBranch,
    ]
}

processResources {
    include 'plugin.yml'
    // Whole lotta boilerplate to get the same functionality as Maven here.
    // Replace this if Gradle ever lets us configure the filter before filtering.
    filter(new Transformer<String, String>() {
        @Override
        String transform(String s) {
            ReplaceTokens replaceTokens = new ReplaceTokens(new StringReader(s))
            replaceTokens.setBeginToken('${')
            replaceTokens.setEndToken('}')
            resourceTokens.forEach { key, val ->
                def token = new ReplaceTokens.Token()
                token.setKey(key.toString())
                token.setValue(val.toString())
                replaceTokens.addConfiguredToken(token)
            }
            return replaceTokens.readLines().join('\n')
        }
    })
}
commented

No idea but just wanna mention that Minecraft 1.21 only runs properly on Java 21

I know its weird that this plugin still uses java 17, if you check the action builds on the repo it also says java 17, but it runs fine in 1.21 despite that, the only issue being that exception that floods your log that was patched and the whole reason I wanted to build this jar anyways.

commented

No idea but just wanna mention that Minecraft 1.21 only runs properly on Java 21

commented

Use Maven build. I successfully built it.

Changing pom.xml to have <project.branch>development</project.branch> in place of <project.branch></project.branch> AND building with maven instead of gradle seems to have fixed it, the plugin loads and starts without issue on my server now.

I don't know what the issue with gradle was but I have much more experience with gradle over maven so for anyone looking at this issue in the future, the command is mvn package to have it package the jar file for you, doing mvn compile alone just compiles it to the classes folder without packaging it into the jar file.