A library to download, relocate & load dependencies during runtime for Maven dependencies for JVM applications. There is also a Gradle plugin to generate a metadata file, to avoid having to define the dependencies in code.
Uses jar-relocator for relocations during runtime
Looking for something to use with Minecraft? Check out MinecraftDependencyDownload
The group id & artifact were changed in version 1.2.1
from dev.vankka.dependencydownload:<module>
to dev.vankka:dependencydownload-<module>
repositories {
mavenCentral()
}
dependencies {
implementation 'dev.vankka:dependencydownload-runtime:1.3.1'
}
Snapshots
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
implementation 'dev.vankka:dependencydownload-runtime:1.3.2-SNAPSHOT'
}
DependencyManager manager = new DependencyManager(DependencyPathProvider.directory(Paths.get("cache")));
manager.addDependencies(new StandardDependency("com.example", "examplepackage", "1.0.0", "<hash>", "SHA-256"));
manager.addRelocations(new Relocation("com.example", "relocated.com.example"));
Executor executor = Executors.newCachedThreadPool();
// All of these return CompletableFuture it is important to let the previous step finishing before starting the next
manager.downloadAll(executor, Collections.singletonList(new StandardRepository("https://repo.example.com/maven2"))).join();
manager.relocateAll(executor).join();
manager.loadAll(executor, classpathAppender).join(); // ClasspathAppender is a interface that you need to implement to append a Path to the classpath
plugins {
id 'dev.vankka.dependencydownload.plugin' version '1.3.1'
}
dependencies {
runtimeDownload 'some:dependency:x.y.z'
runtimeDownloadOnly 'some.other:dependency:x.y.z'
}
jar.dependsOn generateRuntimeDownloadResourceForRuntimeDownloadOnly, generateRuntimeDownloadResourceForRuntimeDownload
This would generate two files runtimeDownloadOnly.txt
and runtimeDownload.txt
shadow is supported to include the relocations in the generated metadata files
DependencyManager manager = new DependencyManager(DependencyPathProvider.directory(Paths.get("cache")));
manager.loadResource(DependencyDownloadResource.parse(getClass().getResource("runtimeDownloadOnly.txt")));
import dev.vankka.dependencydownload.task.GenerateDependencyDownloadResourceTask
task generateResource(type: GenerateDependencyDownloadResourceTask) {
configuration = project.configurations.runtimeDownload
includeRelocations = true
hashingAlgorithm = 'SHA-256'
file = 'dependencies.txt'
}
Bring the jar minifying to the next extreme
import dev.vankka.dependencydownload.task.GenerateDependencyDownloadResourceTask
plugins {
id 'dev.vankka.dependencydownload.plugin' version '1.3.1'
}
configurations {
jarRelocator
}
repositories {
mavenCentral()
}
dependencies {
implementation('dev.vankka:dependencydownload-runtime:1.3.1') {
exclude module: 'jar-relocator'
}
jarRelocator 'me.lucko:jar-relocator:1.4'
}
task generateJarRelocatorResource(type: GenerateDependencyDownloadResourceTask) {
configuration = project.configurations.jarRelocator
}
processResources.dependsOn generateJarRelocatorResource
DependencyManager manager = new DependencyManager(DependencyPathProvider.directory(Paths.get("cache")));
manager.loadResource(DependencyDownloadResource.parse(getClass().getResource("jarRelocator.txt")));
Executor executor = Executors.newCachedThreadPool(2);
manager.downloadAll(executor, Collections.singletonList(new StandardRepository("https://repo.example.com/maven2"))).join();
manager.loadAll(executor, classpathAppender).join();
// now jar-relocator is in the classpath and we can load (and relocate) dependencies from a regular configuration