Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 months 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 (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-27T13:02:23.000Z (6 months ago)
- Last Synced: 2024-10-11T03:22:10.744Z (3 months 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
[![Maven Central](https://img.shields.io/maven-central/v/dev.vankka/dependencydownload-runtime?label=release)](https://central.sonatype.com/search?q=g%253Adev.vankka+dependencydownload)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/dev.vankka/dependencydownload-runtime?label=dev&server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/#view-repositories;snapshots~browsestorage~dev/vankka)
[![Gradle Plugin Portal](https://img.shields.io/gradle-plugin-portal/v/dev.vankka.dependencydownload.plugin?label=gradle%20plugin)](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
```javaDependencyManager 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.GenerateDependencyDownloadResourceTasktask 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
```