Skip to content
This repository was archived by the owner on Jul 4, 2022. It is now read-only.

LibLoader

Leonhard edited this page Sep 15, 2020 · 22 revisions

Dynamic Library Loader

WIP

Benefits over shading

Due to file size constraints on plugin hosting services like SpigotMC, some plugins with shaded dependencies might eventually become too large to upload. This is especially important for premium resources that require to be hosted on SpigotMC directly and not via a link to a GitHub release.

Also, shading usually requires you to relocate your dependencies - If you forget to do so your plugin might clash with other ones.

Depending on artifacts.

You can easily depend on artifacts by adding a dependencies.json file to your .jar file. Those dependencies will be loaded while your application gets installed as a SimplixApplication (See getting started for more information).

Let's illustrate the usage of the dependency manager with a real-world example. We want to make use of the coroutines that Kotlin provides. The .jar file can be quite big and we plan to reuse it with different plugins so it is wiser to use it as a shared library instead of shading it.

 <dependency>
   <groupId>org.jetbrains.kotlinx</groupId>
   <artifactId>kotlinx-coroutines-core</artifactId>
   <version>1.3.9</version>
  <scope>provided</scope> <!-- Must be provided now -->
</dependency>

How would our dependencies.json look like now?

{
  "repositories": [
    {
      "id": "central",
      "url": "https://repo1.maven.org/maven2/"
    },
    {
      "id": "jcenter",
      "url": "http://jcenter.bintray.com"
    }
  ],
  "dependencies": [
    {
      "groupId": "org.jetbrains.kotlinx",
      "artifactId": "kotlinx-coroutines-core",
      "version": "1.3.9"
    }
  ]
}

This is everything codewise we need. Now let's see what will happen when our application starts up.

[18:51:54 INFO] [dev.simplix.core.common.libloader.SimpleLibraryLoader]: [Simplix | LibLoader] Loaded encapsulated library kotlinx-coroutines-core-1.3.9.jar for application Example

Depending on plugins.

You can also depend on plugins that will need to be enabled for your plugin to work. Let's assume that one of your plugins requires the Protocolize plugin to work.

{
  "repositories": [
    {
      "id": "exceptionflug",
      "url": "https://mvn.exceptionflug.de/repository/exceptionflug-public/"
    }
  ],
  "dependencies": [
    {
      "groupId": "de.exceptionflug",
      "artifactId": "protocolize-plugin",
      "version": "${protocolize.version}",
      "type": "plugin"
    }
  ]
}

Now let's see the log output:

[19:27:28 INFO] [dev.simplix.core.common.inject.SimplixInstaller]: [Simplix | Bootstrap] Example: Load dependency de.exceptionflug:protocolize-plugin:1.6.5-SNAPSHOT from repository...

And now let's see our plugins folder.

Clone this wiki locally