Is there a way to make one JAR for Sponge and Spigot/Bukkit?`

Hey guys,
I am working on a universal “core” plugin for my servers (banning, permissions, & general stuff). I plan to use it on my Sponge & Spigot server.

I want do one jar due to a lot of common code between those (HTTP API contacting, MySQL databases & general utils) + I want both plugin versions to be the same.

Does anybody know how can I achieve this?

I don’t think you can put both things in one jar, but, what you can do:

Setup a multi project environment in which you have a common, a sponge and a spigot module and then the later two modules output their specific jars, but for you that would be in the end just one more click.

There’s some projects on GitHub that work like that already if you need an idea

@J3lackSpirit Can you send me example plugin that does such thing?

GitHub - NuVotifier/NuVotifier: A fork of Votifier, with more robust code and vote forwarding NuVotifier does, Grief Defender, and many other larger projects.

There are premade “common” modules that are designed for both Sponge and Bukkit that take advantage of all parts of a server (not just the ones for your plugin) so could save you some time there.

One example is my own ShipsCore (shamelessly plugging at my own stuff I know :wink: )

And yes you can have a single jar run on both Bukkit and Sponge as both Sponge and Bukkit have completely different launch patterns

Well, the problem is that I don’t know how to set it + I don’t see ShipsCore on ur GitHub…

You can see all the source code for the translation layer.

The sponge implementation is for API 8, there are currently parts missing from the Sponge one but it wont be too long before I get those up and running

Hmmm, we kinda misunderstood each other here.

I am not asking how to do the commons thingy. I am asking how to properly set up the project here.

I use InteliJ IDEA with gradle build.

Ahhhh. Ok.

So this is how i would do it.

  1. Create the project as if it was the main plugin.
  2. click file → new module (have this named API or something - this will be what your plugin talks to)
  3. click that new module and then add another module and then have that as either Bukkit or Sponge implementation
  4. do the same as 3 only for the other implementation

Next gradle setup - im not too used to gradle so there is probably a better way to do this

  1. inside the Bukkit or Sponge implementations build.gradle file. Make it a multimodule project by "include"ing the main plugin module and the api module

  2. make the implementation depend upon those modules marked with API classpath.

  3. set up the build.gradle file like it was just a bukkit or sponge plugin (such as add spongeGradle, etc)

  4. repeat 5 - 7 for the other implementation

If everything went right you should be able to do the following command when in the main plugin directory

gradlew build

And have it produce a jar file in each implementation build folder

One more… is there a way to globally declare dependency?

yeah sort of, gradle has a AllProjects property where all the “include” projects (and itself) will get the properties specified (this includes dependencies). Not sure if there is a way to do it for both implementations (maybe able to do all projects in the plugins build.gradle)