Class LibraryLoaderUtil

java.lang.Object
dev.cwhead.GravesX.util.LibraryLoaderUtil

public final class LibraryLoaderUtil extends Object
Utility class for loading external libraries dynamically using BukkitLibraryManager.

This class provides methods to load libraries from Maven repositories, with support for relocation and isolation of the loaded libraries.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new LibraryLoaderUtil instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    loadLibrary(String groupID, String artifactID, String version)
    Loads a library using the given group ID, artifact ID, and version.
    void
    loadLibrary(String groupID, String artifactID, String version, boolean isIsolated)
    Loads a library with the specified group ID, artifact ID, version, and isolation flag.
    void
    loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated)
    Loads a library with relocation and isolation settings.
    void
    loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, boolean resolveTransitiveDependencies)
    Loads a library with relocation, isolation, and transitive dependency settings.
    void
    loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, String libraryURL)
    Loads a library with relocation, isolation, and custom repository URL.
    void
    loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, String libraryURL, boolean resolveTransitiveDependencies)
    Loads a library with relocation, isolation, custom repository URL, and transitive dependency settings.
    void
    loadLibrary(String groupID, String artifactID, String version, String ID, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, String libraryURL, boolean resolveTransitiveDependencies)
    Loads a library into the runtime using the BukkitLibraryManager.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LibraryLoaderUtil

      public LibraryLoaderUtil(Graves plugin)
      Constructs a new LibraryLoaderUtil instance.
      Parameters:
      plugin - The plugin instance to associate with the library manager.
  • Method Details

    • loadLibrary

      public void loadLibrary(String groupID, String artifactID, String version)
      Loads a library using the given group ID, artifact ID, and version.

      Uses default values: no relocation, no loader ID, non-isolated, no custom repository URL, and resolves transitive dependencies.

      Parameters:
      groupID - (Required) Maven group ID of the library.
      artifactID - (Required) Maven artifact ID of the library.
      version - (Required) Version of the library.
    • loadLibrary

      public void loadLibrary(String groupID, String artifactID, String version, boolean isIsolated)
      Loads a library with the specified group ID, artifact ID, version, and isolation flag.

      Uses default values: no relocation, no loader ID, no custom repository URL, and resolves transitive dependencies.

      Parameters:
      groupID - (Required) Maven group ID of the library.
      artifactID - (Required) Maven artifact ID of the library.
      version - (Required) Version of the library.
      isIsolated - (Required) Whether the library should be loaded in an isolated class loader.
    • loadLibrary

      public void loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated)
      Loads a library with relocation and isolation settings.

      Uses default values: no loader ID, no custom repository URL, and resolves transitive dependencies.

      Parameters:
      groupID - (Required) Maven group ID of the library.
      artifactID - (Required) Maven artifact ID of the library.
      version - (Required) Version of the library.
      relocatePattern - (Optional) Original package pattern to relocate (requires relocated pattern).
      relocateRelocatedPattern - (Optional) Target package pattern for relocation (requires original pattern).
      isIsolated - (Required) Whether the library should be loaded in an isolated class loader.
    • loadLibrary

      public void loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, boolean resolveTransitiveDependencies)
      Loads a library with relocation, isolation, and transitive dependency settings.

      Uses default values: no loader ID, no custom repository URL.

      Parameters:
      groupID - (Required) Maven group ID of the library.
      artifactID - (Required) Maven artifact ID of the library.
      version - (Required) Version of the library.
      relocatePattern - (Optional) Original package pattern to relocate (requires relocated pattern).
      relocateRelocatedPattern - (Optional) Target package pattern for relocation (requires original pattern).
      isIsolated - (Required) Whether the library should be loaded in an isolated class loader.
      resolveTransitiveDependencies - (Required) Whether to resolve transitive dependencies.
    • loadLibrary

      public void loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, String libraryURL)
      Loads a library with relocation, isolation, and custom repository URL.

      Uses default values: no loader ID, resolves transitive dependencies.

      Parameters:
      groupID - (Required) Maven group ID of the library.
      artifactID - (Required) Maven artifact ID of the library.
      version - (Required) Version of the library.
      relocatePattern - (Optional) Original package pattern to relocate (requires relocated pattern).
      relocateRelocatedPattern - (Optional) Target package pattern for relocation (requires original pattern).
      isIsolated - (Required) Whether the library should be loaded in an isolated class loader.
      libraryURL - (Optional) Custom repository URL; if null, defaults are used.
    • loadLibrary

      public void loadLibrary(String groupID, String artifactID, String version, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, String libraryURL, boolean resolveTransitiveDependencies)
      Loads a library with relocation, isolation, custom repository URL, and transitive dependency settings.

      Uses default values: no loader ID.

      Parameters:
      groupID - (Required) Maven group ID of the library.
      artifactID - (Required) Maven artifact ID of the library.
      version - (Required) Version of the library.
      relocatePattern - (Optional) Original package pattern to relocate (requires relocated pattern).
      relocateRelocatedPattern - (Optional) Target package pattern for relocation (requires original pattern).
      isIsolated - (Required) Whether the library should be loaded in an isolated class loader.
      libraryURL - (Optional) Custom repository URL; if null, defaults are used.
      resolveTransitiveDependencies - (Required) Whether to resolve transitive dependencies.
    • loadLibrary

      public void loadLibrary(String groupID, String artifactID, String version, String ID, String relocatePattern, String relocateRelocatedPattern, boolean isIsolated, String libraryURL, boolean resolveTransitiveDependencies)
      Loads a library into the runtime using the BukkitLibraryManager.

      Required: groupID, artifactID, version, isIsolated, resolveTransitiveDependencies.
      Optional: ID, relocatePattern + relocateRelocatedPattern (must be provided together), libraryURL.

      If libraryURL is null or blank, common repositories (Maven Central, Sonatype, JCenter, JitPack) are registered. If relocation is requested, both patterns must be non-blank. When isIsolated is true and ID is blank, a stable loaderId of artifactID + "-isolated" is used.

      Parameters:
      groupID - (Required) Maven group ID (use "{}" as dot placeholders; replaced with "." in logs/messages only).
      artifactID - (Required) Maven artifact ID.
      version - (Required) Library version to resolve.
      ID - (Optional) Loader ID for namespacing (recommended when isolated).
      relocatePattern - (Optional) Original package pattern to relocate; requires relocateRelocatedPattern.
      relocateRelocatedPattern - (Optional) Target package pattern for relocation; requires relocatePattern.
      isIsolated - (Required) Whether to load the library in an isolated class loader.
      libraryURL - (Optional) Custom repository URL to resolve from; if blank, defaults are used.
      resolveTransitiveDependencies - (Required) Whether to resolve transitive dependencies.
      Throws:
      IllegalArgumentException - if any required parameter is null/blank, or only one relocation pattern is provided.