Skip to content

Latest commit

 

History

History
113 lines (75 loc) · 3.88 KB

README.md

File metadata and controls

113 lines (75 loc) · 3.88 KB

PDM

The Plugin Dependency Manager

Build Status

Latest Runtime Version

Gradle Plugin Version

Discord

PDM Demo

PDM IS STILL IN ALPHA! - Nothing is guaranteed to work and every update could include breaking changes!

PDM aims to reduce the amount of shading that plugin authors have to do by creating a central repository for storing libraries.

This is done in the form of a new directory - plugins/PluginLibraries

Jars are downloaded to this directory and loaded into the classpath of plugins that need them.

Why is this useful?

  • Reduce overall Jar Size
  • No need to relocate dependencies
  • Reduce build time when dealing with many libraries
  • PDM is small! It uses absolutely no external dependencies that aren't provided by Spigot, making the size footprint of using it tiny - less than 50 KB!

How to Use

PDM is incredibly simple. Usage involves 2 processes:

  1. Declaring Dependencies
  2. Loading Dependencies

Declaring Dependencies

There are 2 ways of doing Dependency Declaration:

  1. Programmatically
  2. JSON File

Declaration can be done programmatically or via JSON file:

Programmatically (Java):

Create a new PluginDependencyManager with SpigotDependencyManager.of(Plugin), and call PluginDependencyManager#loadAllDependencies

For example:

PluginDependencyManager dependencyManager = SpigotDependencyManager.of(this);
CompletableFuture<Void> onLoad = dependencyManager.loadAllDependencies();
//loadAllDependencies is async, the returned future is completed when downloading and loading completes
onLoad.thenRun(() -> System.out.println("Everything is loaded!"));

JSON Based: Make a file called dependencies.json in your resources directory.

It should follow a format similar to this example:

{
  "repositories": {
    "jitpack": "https://jitpack.io"
  },
  "dependencies": [
    {
      "groupId": "com.github.knightzmc",
      "artifactId": "fluency",
      "version": "1.0",
      "repository": "jitpack"
    }
  ]
}

This file's contents will be loaded automatically and downloaded.

Loading

Loading the dependencies is as simple as calling PluginDependencyManager#loadAllDependencies

This will return a CompletableFuture<Void> which is completed when all libraries are loaded.

That's it! All dependencies should be downloaded and loaded into the classpath, including transitive dependencies. Any that failed will be logged and handled gracefully.

Gradle Plugin

PDM also includes a Gradle Plugin to automatically generate a dependencies.json file! This is the recommended approach, as it does 99% of the work for you and is much more extendable.

This is a basic example of the usage:

plugins {
  id "me.bristermitten.pdm" version "0.0.28" //Replace with the latest version 
}

dependencies {
    compileOnly "org.spigotmc:spigot-api:1.16.3-R0.1-SNAPSHOT"
    pdm "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72" //This will be added to the dependencies.json
}

jar.dependsOn project.tasks.getByName("pdm") //Always run the pdm task when we build. Alternatively, just run [gradle pdm build]

A full example can be found here.