0

I'm writing a lot of plugins for minecraft bukkit server's and I've grown tired of copy+pasting the same utility classes in my projects all over again. I decided to just put them all in a separate project and add them to my plugins via maven. I'm using IntelliJ Ultimate.

I want to have a maven project that contains all my utitily classes called e.g. UtilityAPI. Then I want to be able to create another project, which will be my bukkit plugin. In this second project I want to be able to use all the code from the first one. Also, I'd like it very much, that if I choose to build a plugin jar, maven automatically takes into account the most recent code from my API-Project.

I started working on this and started reading about maven modules and how you can use them to forge different projects together. I initially thought, that this was just what I needed, and tried to just add

<modules>
    <module>UtilityAPI</module>
</modules>

However this results in my bukkit plugin project being considered a parent project, and refuses to build in a jar, but just in a (at least for me) rather useless .pom file. I'm not sure how to proceed. Do I have to create a "parent" project for my bukkit plugin project which contains the api and the plugin project as modules? And if yes, how do I generate a .jar, and not a .pom?

The dream solution would be to have the UtilityAPI project, and being able to include it in any new plugins that I might write in the future. I'd also be a fan of having a simple way to create a jar with the newest sources of my plugin in it. Is this possible, and if yes, how?

monamona
  • 1,195
  • 2
  • 17
  • 43

1 Answers1

1

In your Maven multi-module project your plugin would have to be another module (and not the parent, which has packaging type pom). This module would then have a dependency on the API module (dependencies between modules are possible).

However, multi-module projects are usually intended for projects which are tightly coupled. That does not appear to be the case for your scenario. It sounds like the plugins have (potentially) nothing in common except for the dependency on the API project. Maybe it would be better to have the API project as separate standalone Maven project and then deploy snapshot versions of it (or install them only to your local Maven repository) and use these in your plugin projects.

Marcono1234
  • 5,856
  • 1
  • 25
  • 43
  • Hmm, okay, I will do that. Is there a way to tell intellij that I want to first install the newest version of my API-Project and then build my actual Plugin? – monamona Dec 21 '20 at 20:07
  • 1
    @monamona, if you are only doing local development, then it appears you can open multiple Maven projects in IntelliJ at the same time and (according to the answers) IntelliJ builds the projects without you having to manually build the projects, see https://stackoverflow.com/questions/8774024/intellij-working-on-multiple-projects; however I have not tested it. Though when you want to create the `.jar` file you likely still have to run the Maven commands manually. – Marcono1234 Dec 21 '20 at 20:38