CryptoMorin / XSeries

Library for cross-version Minecraft Bukkit support and various efficient API methods.
https://www.spigotmc.org/threads/378136/
MIT License
403 stars 126 forks source link

[XSkull] - Authlib version does not support Java 8 #295

Closed Tohjuler closed 2 months ago

Tohjuler commented 2 months ago

Description The version of authlib that the README tell you to use (6.0.54), does not work in Java 8 as it is compiled in java 17.

Note: The version 1.5.21 does work, but don't know if it is the best to use.

Version Not relevant.

CryptoMorin commented 2 months ago

When you say it doesn't "work" in what way exactly are you checking this? Are you saying you can't compile your plugin or are you saying it fails to load in a server that uses Java 8 (and if this is the case, what version did you test this with, post the error)?

Tohjuler commented 2 months ago

Sorry for the late answer. It can't compile. Like i said, the version 6.0.54 of the lib is compiled in java 17, and is not comparable with java 8, as java is not forward comparable. Just tested and version 1.11 does also work with java 8.

CryptoMorin commented 2 months ago

You should always use the latest LTS version of Java for your IDE but configure your build tool to compile it as Java 8

Tohjuler commented 2 months ago

That does not change anything, the error happens when i compile the plugin with java 8. Here is the error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project McUtils: Compilation failure
[ERROR] /C:/Coding/Minecraft/Libs/McUtils/src/main/java/dk/tohjuler/mcutils/items/SkullCreator.java:[92,59] cannot access com.mojang.authlib.GameProfile
[ERROR]   bad class file: C:\Users\tobia\.m2\repository\com\mojang\authlib\6.0.54\authlib-6.0.54.jar(com/mojang/authlib/GameProfile.class)
[ERROR]     class file has wrong version 61.0, should be 52.0
[ERROR]     Please remove or make sure it appears in the correct subdirectory of the classpath.
CryptoMorin commented 2 months ago

I can't reproduce it.

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
    <repository>
        <id>minecraft-libraries</id>
        <name>Minecraft Libraries</name>
        <url>https://libraries.minecraft.net/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.21-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.github.cryptomorin</groupId>
        <artifactId>XSeries</artifactId>
        <version>11.2.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.mojang</groupId>
        <artifactId>authlib</artifactId>
        <version>6.0.54</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.13.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
public class SimplePluginMain extends JavaPlugin {
    @Override
    public void onEnable() {
        com.mojang.authlib.GameProfile.class.getSimpleName();
        XSkull.createItem()
                .profile(Profileable.of(Bukkit.getOnlinePlayers().stream().findFirst().orElse(null)))
                .apply();
    }
}
jdk-21 "-Dmaven.multiModuleProjectDirectory=SimpleMavenPlugin" -Djansi.passthrough=true --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 clean package
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< org.simple.plugin1:SimpleMavenPlugin >----------------
[INFO] Building SimpleMavenPlugin 1.0.0
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ SimpleMavenPlugin ---
[INFO] Deleting ...\SimpleMavenPlugin\target
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ SimpleMavenPlugin ---
[INFO] Copying 0 resource from src\main\resources to target\classes
[INFO] 
[INFO] --- compiler:3.13.0:compile (default-compile) @ SimpleMavenPlugin ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 1 source file with javac [debug target 1.8] to target\classes
[WARNING] bootstrap class path not set in conjunction with -source 8
[WARNING] source value 8 is obsolete and will be removed in a future release
[WARNING] target value 8 is obsolete and will be removed in a future release
[WARNING] To suppress warnings about obsolete options, use -Xlint:-options.
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ SimpleMavenPlugin ---
[INFO] skip non existing resourceDirectory ...\SimpleMavenPlugin\src\test\resources
[INFO] 
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ SimpleMavenPlugin ---
[INFO] Recompiling the module because of changed dependency.
[INFO] 
[INFO] --- surefire:3.2.2:test (default-test) @ SimpleMavenPlugin ---
[INFO] 
[INFO] --- jar:3.3.0:jar (default-jar) @ SimpleMavenPlugin ---
[INFO] Building jar: ...\SimpleMavenPlugin\target\SimpleMavenPlugin-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.295 s
[INFO] Finished at: 2024-08-30
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0
 javap -v SimplePluginMain.class | grep major
major version: 52
Tohjuler commented 2 months ago

Oh, i don't use the maven-compiler-plugin plugin and my SDK is java 8, so it compiles with the java 8 exe.

CryptoMorin commented 2 months ago

It doesn't matter if you didn't specify maven-compiler-plugin in your pom.xml, you're implicitly using it. I was just showing you two different ways to set your build tool to use Java 8 to compile. One is <properties> tag and the other is inside the <configuration> tag. Using either works.

And yes, like I said, you need to change your IDE's Java version (the SDK you mentioned) to the latest LTS version (which would be Java 21).

Tohjuler commented 2 months ago

Okay, sorry for taking your time.