Solved How to compile for all Java Versions ?

Discussion in 'Spigot Plugin Development' started by Wythe, Jul 10, 2021.

  1. Hello,

    i updated my plugin to 1.17 the problem is that older versions now also require java 16.
    Is it possible to compile it for all Java versions e.g. 8+ ?

    I know that the java features of my plugins should work for java 8+, the issue is the the following error:

    Code (Text):
    [ERROR]   bad class file: /home/ false/git/Builder-s-Wand/../all-spigot-nms/all-spigot-nms.jar(/net/minecraft/nbt/NBTTagCompound.class)
    [ERROR]     class file has wrong version 60.0, should be 57.0
    As the all-spigot-nms.jar is a class which contains all spigot versions it was compiled with java 16 as 1.17 needs java 16.
    Thats the reason why i can't compile the it with java versions which are < java 16.
    Or is there a better way to get all spigot versions in intellj/maven instead of the project ?

  2. Hello, i think you can but you need to create script or use gitlab CI to do it. Or you need to compile your plugin for all version...
  3. As example fawe has one jar which supports java 11+, so i don't think i need to compile it for all versions...
  4. Just compile for Java 8. There's nothing else to do because newer JVMs will still be able to load your classes. Java is backwards compatible.
    • Like Like x 2
    • Agree Agree x 2
  5. Make sure you use the new SDK, but compile for Java 8 (lambdas and language too) - it'll work for any server with 8+.
    • Like Like x 1
  6. Using the new SDK isn't even required, but if you do, you can take advantage of the --release compiler option which will not only set the source and bytecode level, but will also check that you don't any apis from the standard library that were introduced in later releases.
    If you're using Maven, then this is as easy as setting
    Code (XML):
    in the configuration of the maven-compiler-plugin.
    • Like Like x 1
  7. As i wrote in the first post, if i try to compile the plugin with a java version smaller then 16 i get the following issue.
    Code (Text):
    [ERROR]  bad class file: /home/ false/git/Builder-s-Wand/../all-spigot-nms/all-spigot-nms.jar(/net/minecraft/nbt/NBTTagCompound.class)
    [ERROR]     class file has wrong version 60.0, should be 57.0
    The resaon is that i use the all-nms project (see last post), so i have all versions for autocomplete etc.
    The maven part looks like this:

    Code (Text):
    Which means i can't compile it java 8 as easy as you said :D

    I did, same for you.
  8. Ahh you're using server internals? In that case you can set up a multi-module maven build with a sub-module for each nms version (I do this in my plugin InvSee++). This way I can set the dependencies and compiler options per submodule, and I use the maven-shade-plugin to bundle all classes from the submodules in the plugin's fat jar.
  9. I mean i saw that a few years ago..
    If i remember correctly, i have to create a folder for each NMS class and each folder has a pom file with the spigot version as dependency (which repository do you use for that ?)
    In the main pom i only have to declare the modules, right ?
  10. Correct! My code is on github, feel free to use it as an example.
  11. I'm not familiar with maven, your plugin pom has a lot of stuff which i never used.
    Is that all needed ? For example the remap stuff ?
    Also you are using your own repository, right ?
    Is there no public one ?
  12. The remap stuff is only necessesary if you use the mojang class names, field names and method names for the nms classes.
    I am using the local repository because no-one is allowed to distribute a compiled version of Spigot publicly because that would violate the license as set by Mojang.
    #12 Jannyboy11, Jul 10, 2021
    Last edited: Jul 11, 2021
    • Like Like x 1
  13. Is there no public maven repository from spigot ?
    If not every dev has to setup a own maven repository ? ;o
  14. Running BuildTools will automatically install the compiled .jar to your local repo
  15. Thanks, i will try it.

    Good to know, thank you!
  16. I reorganized my code in modules, now i have one last issue (i hope so).
    I get this error:
    Code (Text):
     /home/false/git/Builder-s-Wand/Spigot_Plugin/src/main/java/de/False/BuildersWand/utilities/[5,37] package de.False.BuildersWand.version does not exist
    The package "de.False.BuildersWand.version.NMS" is in the new module "Builders_Wand_abstraction" which only contains the interface for my nms modules/classes.

    That modules is marked as dependency in my "main" module which contains the source code of the plugin.
    Code (Text):
    So i don't understand why the package "does not exists" if i marked the module as dependeny.
    Any suggestions ?
  17. Nobody have a idea ?
  18. All the maven tasks should be run from the project root. If you're in a submodule and run a maven task, then the other modules are not available.
  19. Fixed that issue, was a stupid mistake from me..
    While refactoring to modules, i just did c&p for the module structure.. but i missed the "main" folder.