{"id":14985681,"url":"https://github.com/revxrsal/pluginlib","last_synced_at":"2025-07-25T20:35:59.485Z","repository":{"id":117725978,"uuid":"315601165","full_name":"Revxrsal/PluginLib","owner":"Revxrsal","description":"An extremely simple utility to allow downloading libraries and relocating them at runtime without having to shade them","archived":false,"fork":false,"pushed_at":"2020-12-23T09:16:53.000Z","size":92,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T22:04:11.942Z","etag":null,"topics":["pluginlib","relocation","shade","yml"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Revxrsal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-24T10:46:57.000Z","updated_at":"2024-09-01T07:36:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"a82742fd-e146-48ce-b94e-87ec13938170","html_url":"https://github.com/Revxrsal/PluginLib","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"94f07e378895e6fe5898f110193256bbe97581a2"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revxrsal%2FPluginLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revxrsal%2FPluginLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revxrsal%2FPluginLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revxrsal%2FPluginLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Revxrsal","download_url":"https://codeload.github.com/Revxrsal/PluginLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487716,"owners_count":21112191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pluginlib","relocation","shade","yml"],"created_at":"2024-09-24T14:11:28.641Z","updated_at":"2025-04-11T22:04:57.008Z","avatar_url":"https://github.com/Revxrsal.png","language":"Java","readme":"\n# PluginLib\nA simple utility to allow downloading libraries and relocating them at runtime without having to shade them\n\n# Usage\nSimply extend **pluginlib.DependentJavaPlugin** instead of Bukkit's *JavaPlugin*.\n```java\npackage org.example;  \n  \nimport pluginlib.DependentJavaPlugin;  \n  \npublic class ExamplePlugin extends DependentJavaPlugin {  \n  \n}\n```\n\nTo add libraries, you have 2 ways:\n\n## Through YML (Preferable)\nDefine them in your **plugin.yml** through the `runtime-libraries` section:\n```yml\nname: ExamplePlugin  \nmain: org.example.ExamplePlugin  \nversion: 1.0-SNAPSHOT  \nauthors: [...]  \nruntime-libraries:  \n  relocation-prefix: 'org.example.libs' # Required if we want to relocate libraries  \n  libraries-folder: 'libraries' # If not defined, it will be 'libs'    \n  libraries:  \n    kotlin:\n      groupId: org.jetbrains.kotlin  \n      artifactId: kotlin-stdlib  \n      version: 1.4.20\n```\nHere we want to get **Kotlin**'s standard library. \nUnless explicitly specified, **dependencies will be downloaded from Maven Central**. We can specify the repository we want to get from, using the `repository` property:\n```yml\n   jda:  \n      groupId: net.dv8tion  \n      artifactId: JDA  \n      version: 4.2.0_222\n      repository: https://jcenter.bintray.com/\n```\nThis way, JDA will be downloaded from Bintray JCenter's repository.\n\nThere are multiple ways to define a library, aside from defining the library properties (group id, artifact id, etc) \n\n### Through Maven-like XML\nFor the sake of productivity, and because we love being lazy, you can **straight define the library's XML, much similar to Maven's format**:\n```yml\n    kotlin:  \n      xml: '  \n        \u003cdependency\u003e\n          \u003cgroupId\u003eorg.jetbrains.kotlin\u003c/groupId\u003e \n          \u003cartifactId\u003ekotlin-stdlib\u003c/artifactId\u003e \n          \u003cversion\u003e1.4.20\u003c/version\u003e \n        \u003c/dependency\u003e \n        '\n```\nThis can be especially helpful if you don't want to bother converting the XML to YML, and if you just copied it straight from a website. **Warning: By time, your plugin.yml may get a little unclean if you keep doing this!**\n\n### Defining a URL directly\nSome libraries (although rare), do not follow the standard `repository:/group/artifact/version/artifact-version.jar` format, and may require us to explicitly define the URL we want to download the library from.\n\nLet's imagine we want to use **[Aikar's Minecraft Timings](https://github.com/aikar/minecraft-timings)**:\n```yml\n    timings:  \n      url: 'http://repo.aikar.co/nexus/content/groups/aikar/co/aikar/minecraft-timings/1.0.4/minecraft-timings-1.0.4.jar'\n      artifactId: 'mc-timings'\n      version: 1.0.4\n```\n**Important note**: When we follow this format, we **must** define the artifact ID and the version.\n\nThis can also be useful if what we're looking for is to download a JAR, rather than an actual library.\n\n**Defining in your plugin.yml has a major advantage**: When your plugin loads, libraries will already have been loaded beforehand. \n**This means you can use your library components anywhere in your code, such as static blocks and initializers.**\n\n## Load libraries using code\nYou can also load libraries programmatically, instead of defining them in your plugin.yml. \n\nThis has a few advantages, such as being able to load your library conditionally (for example, we might need to load MySQL drivers only when the chosen database type is MySQL in our config), however it also has the disadvantage of being unable to use your library until it is explicitly loaded.\n\nFor example, if we want to use **[Caffeine](https://github.com/ben-manes/caffeine)**:\n```java\npackage org.example;  \n  \nimport pluginlib.DependentJavaPlugin;  \nimport pluginlib.PluginLib;  \n  \npublic class ExamplePlugin extends DependentJavaPlugin {  \n  \n  private static final PluginLib CAFFEINE = PluginLib.builder()  \n      .groupId(\"com.github.ben-manes.caffeine\")  \n      .artifactId(\"caffeine\")  \n      .version(\"2.8.6\")  \n      .build();  \n  \n  static {  \n        CAFFEINE.load(ExamplePlugin.class);  \n  }  \n  \n}\n``` \n\nJust like the plugin.yml, we can also parse from XML:\n```java\nprivate static final PluginLib CAFFEINE = PluginLib.parseXML(  \n  \"\u003cdependency\u003e\" +  \n  \"  \u003cgroupId\u003ecom.github.ben-manes.caffeine\u003c/groupId\u003e\" +  \n  \"  \u003cartifactId\u003ecaffeine\u003c/artifactId\u003e\" +  \n  \"  \u003cversion\u003e2.8.6\u003c/version\u003e\" +  \n  \"\u003c/dependency\u003e\"  \n).build();\n```\n\nAnd, we can also parse the library from a URL:\n```java\nprivate static final PluginLib TIMINGS = PluginLib  \n        .fromURL(\"https://repo.aikar.co/nexus/content/groups/aikar/co/aikar/minecraft-timings/1.0.4/minecraft-timings-1.0.4.jar\")  \n        .artifactId(\"timings\")  \n        .version(\"1.0.4\")  \n        .build();  \n  \nstatic {  \n    TIMINGS.load(ExamplePlugin.class);  \n}\n```\n\n# Relocating\nRelocation is some re-mapping your code and dependencies to make them unique and not conflict with other plugins or dependencies. For example, if we want to relocate `okhttp3`'s library, its paths would change:\n`okhttp3.OkHttpClient` -\u003e `org.example.okhttp3.OkHttpClient`.\nAnd the same with all other classes that fall in `okhttp3`'s package. If any plugin also includes okhttp3, we will be sure that there will not be any conflicts between our plugin and the others.\n\n## Through YML\nIn our library's definition, we simply add the `relocation` section\n```yml\n  jda:  \n    groupId: net.dv8tion  \n    artifactId: JDA  \n    version: 4.2.0_222  \n    repository: https://jcenter.bintray.com/  \n    relocation:  \n      net.dv8tion.jda: jda\n```\nRelocation follows the following template:\n`\u003clibrary name\u003e: 'path to replace'`\nlibrary name would be `jda`, and in relocation it would appear as **\\\u003crelocation prefix\u003e.\\\u003clibrary name\u003e**, as in, **org.example.libs.jda**.\n\n## Through code\nWe can specify relocation rules through our code in the builder:\n```java\npackage org.example;  \n  \nimport pluginlib.DependentJavaPlugin;  \nimport pluginlib.PluginLib;  \nimport pluginlib.Relocation;  \n  \npublic class ExamplePlugin extends DependentJavaPlugin {  \n  \n  private static final PluginLib CAFFEINE = PluginLib.builder()  \n        .groupId(\"com.github.ben-manes.caffeine\")\n        .artifactId(\"caffeine\")\n        .version(\"2.8.6\")\n        .relocate(new Relocation(\"com/github/benmanes/caffeine\", \"org.example.libs.caffeine\"))\n        .build();\n  \n  static {  \n      CAFFEINE.load(ExamplePlugin.class);  \n  }  \n}\n```\n\n\n**Very important note**: Relocating using plugin.yml or code **is not enough!** You must tell your build system (Maven or Gradle) to relocate references in your code as well.\n\n* Relocating in **[Maven](https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html)**\n* Relocating in **[Gradle](https://imperceptiblethoughts.com/shadow/configuration/relocation/)**\n\nNotice that we did not directly put `com.github.benmanes`, and instead `com/github/benmanes`. This way, we will be able to outsmart build system relocation, and will not have this very string literal relocated.\n\n# Full examples  \nYou can view full examples in **[maven](https://github.com/ReflxctionDev/PluginLib/tree/maven)** and **[gradle](https://github.com/ReflxctionDev/PluginLib/tree/gradle)** branches.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevxrsal%2Fpluginlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frevxrsal%2Fpluginlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevxrsal%2Fpluginlib/lists"}