Last active
June 12, 2025 16:13
-
-
Save daviddenton/6a14bf99f3b9bdbf5e2e5306637fc715 to your computer and use it in GitHub Desktop.
download gradle 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
tasks.register<Copy>("downloadDependencies") { | |
from(configurations.runtimeClasspath) | |
into("local-repo/jars") | |
} | |
tasks.register("downloadDependenciesWithMetadata") { | |
doLast { | |
configurations.runtimeClasspath.get().resolvedConfiguration.resolvedArtifacts.forEach { artifact -> | |
val moduleVersion = artifact.moduleVersion.id | |
val group = moduleVersion.group.replace(".", "/") | |
val name = moduleVersion.name | |
val version = moduleVersion.version | |
// Copy JAR | |
copy { | |
from(artifact.file) | |
into("local-repo/$group/$name/$version/") | |
} | |
// Download POM | |
val pomUrl = "${repositories.maven.url}/$group/$name/$version/$name-$version.pom" | |
val pomFile = file("local-repo/$group/$name/$version/$name-$version.pom") | |
pomFile.parentFile.mkdirs() | |
try { | |
URL(pomUrl).openStream().use { inputStream -> | |
pomFile.outputStream().use { outputStream -> | |
inputStream.copyTo(outputStream) | |
} | |
} | |
} catch (e: Exception) { | |
println("Failed to download POM for $moduleVersion: ${e.message}") | |
} | |
} | |
} | |
} |
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
<settings> | |
<localRepository>./temp-m2-repo</localRepository> | |
<!-- Copy your existing repository/server configs if needed --> | |
<servers> | |
<server> | |
<id>your-private-repo</id> | |
<username>your-username</username> | |
<password>your-password</password> | |
</server> | |
</servers> | |
</settings> |
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
<settings> | |
<localRepository>./temp-m2-repo</localRepository> | |
<!-- Copy your existing repository/server configs if needed --> | |
<servers> | |
<server> | |
<id>your-private-repo</id> | |
<username>your-username</username> | |
<password>your-password</password> | |
</server> | |
</servers> | |
</settings> |
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
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-dependency-plugin</artifactId> | |
<version>3.6.0</version> | |
<executions> | |
<execution> | |
<id>copy-dependencies</id> | |
<phase>package</phase> | |
<goals> | |
<goal>copy-dependencies</goal> | |
</goals> | |
<configuration> | |
<outputDirectory>${project.build.directory}/maven-repo</outputDirectory> | |
<useRepositoryLayout>true</useRepositoryLayout> | |
<copyPom>true</copyPom> | |
<includeScope>compile</includeScope> | |
<includeScope>runtime</includeScope> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment