Last active
April 25, 2024 16:14
-
-
Save nniesen/3257f341585c697545137deb7df34c65 to your computer and use it in GitHub Desktop.
Gradle copy libraries from configuration dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of extracting a dependency (e.g., jar, dll, so, etc...) from a configurations dependencies. | |
// Useful for running things locally (cli, db driver, etc) and need easy way to extract resolved version used by project. | |
repositories { | |
mavenCentral() | |
} | |
configurations { | |
nativeLibraries { transitive = false } | |
} | |
dependencies { | |
nativeLibraries 'org.mongodb:mongodb-driver-sync:5.0.1' | |
} | |
task extractNativeLibraries(type: Copy) { | |
println "FILE=${configurations.nativeLibraries.singleFile}" | |
from zipTree(configurations.nativeLibraries.singleFile).matching { | |
//include 'libs/**' | |
} | |
into "${buildDir}/nativeLibs" | |
} | |
assemble.dependsOn(extractNativeLibraries) | |
// Example of extracting a dependency (e.g., jar, dll, so, etc...) from a configurations dependencies. | |
// Useful for running things locally (cli, db driver, etc) and need easy way to extract resolved version used by project. | |
task copyLibraries(type: Copy, description: 'Copy libraries from configuration dependency') { | |
into "build/libs" // <- some location | |
from (buildscript.configurations.classpath) { // <- some configuration | |
include '**/springloaded-*.jar' // <- some dependency | |
rename '([a-zA-Z0-9]*)-.*\\.jar', '$1.jar' // Remove version info | |
} | |
} | |
tasks.eclipse.dependsOn(copyLibraries) // <- some dependency | |
// Another version | |
task copyRuntimeDependencies(type: Copy) { | |
dependsOn 'jar' | |
from configurations.runtimeClasspath.filter({ f -> !(f.toString() =~ "kotlin|annotations") }) | |
into 'build/libs' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment