https://github.com/vankka/dependencydownload
A Java library (& Gradle plugin) to download dependencies during runtime with ease
https://github.com/vankka/dependencydownload
dependency-management gradle-plugin java
Last synced: about 1 year ago
JSON representation
A Java library (& Gradle plugin) to download dependencies during runtime with ease
- Host: GitHub
- URL: https://github.com/vankka/dependencydownload
- Owner: Vankka
- License: mit
- Created: 2021-06-09T19:28:13.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-27T13:02:23.000Z (over 1 year ago)
- Last Synced: 2024-10-11T03:22:10.744Z (over 1 year ago)
- Topics: dependency-management, gradle-plugin, java
- Language: Java
- Homepage:
- Size: 338 KB
- Stars: 29
- Watchers: 1
- Forks: 4
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# DependencyDownload
[](https://central.sonatype.com/search?q=g%253Adev.vankka+dependencydownload)
[](https://s01.oss.sonatype.org/#view-repositories;snapshots~browsestorage~dev/vankka)
[](https://plugins.gradle.org/plugin/dev.vankka.dependencydownload.plugin)
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](https://github.com/lucko/jar-relocator/) for relocations during runtime
Looking for something to use with Minecraft? [Check out MinecraftDependencyDownload](https://github.com/Vankka/MinecraftDependencyDownload/)
## Dependency
## ⚠️ Group Id & Artifact Id change
The group id & artifact were changed in version `1.2.1` from `dev.vankka.dependencydownload:` to `dev.vankka:dependencydownload-`
```groovy
repositories {
mavenCentral()
}
dependencies {
implementation 'dev.vankka:dependencydownload-runtime:1.3.1'
}
```
Snapshots
```groovy
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
implementation 'dev.vankka:dependencydownload-runtime:1.3.2-SNAPSHOT'
}
```
## Usage
```java
DependencyManager manager = new DependencyManager(DependencyPathProvider.directory(Paths.get("cache")));
manager.addDependencies(new StandardDependency("com.example", "examplepackage", "1.0.0", "", "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
```
## Gradle plugin
```groovy
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`
### ShadowJar support
[shadow](https://github.com/johnrengelman/shadow) is supported to include the relocations in the generated metadata files
### Loading dependencies from a plugin generated file
```java
DependencyManager manager = new DependencyManager(DependencyPathProvider.directory(Paths.get("cache")));
manager.loadResource(DependencyDownloadResource.parse(getClass().getResource("runtimeDownloadOnly.txt")));
```
### Customizing
```groovy
import dev.vankka.dependencydownload.task.GenerateDependencyDownloadResourceTask
task generateResource(type: GenerateDependencyDownloadResourceTask) {
configuration = project.configurations.runtimeDownload
includeRelocations = true
hashingAlgorithm = 'SHA-256'
file = 'dependencies.txt'
}
```
## Download `jar-relocator` during runtime
Bring the jar minifying to the next extreme
```groovy
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
```
```java
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
```