Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle : Get all files in a dependency from maven repository

I want to add all the files available in a dependency to my artifacts so I can upload that dependency to another Nexus repository.

My dependency contains 15 files stored in my Nexus repository under the same GAV :

myproject.jar
myproject.jar.md5
myproject.jar.sha1

myproject-sources.jar
myproject-sources.jar.md5
myproject-sources.jar.sha1

myproject.tgz
myproject.tgz.md5
myproject.tgz.sha1

myproject.pom
myproject.pom.md5
myproject.pom.sha1

maven-metadata.xml
maven-metadata.xml.md5
maven-metadata.xml.sha1

The -sources.jarfile has a <classifier>sources</classifier>property, the tgz and pom files have an <extension>property and the others have nothing special.

The thing is I would like to avoid hardcoding as much as possible, to be able to pass only the GAV parameters to my script and it can handle all the fetching and releasing on its own for any GAV, no matter what files are available.

The solution I'm working on right now is to query directly the Nexus repo to get the files list with an url like this :

http://mynexushost:8081/nexus/service/local/repositories/snapshots/content/${group}/${artifact}/${version}/

That sends me a JSON (with the accept header set to application/json) containing the URLs and stuff I need to retreive all the files available, download them and add them to my artifacts, then upload it to my target repository.

I'm pretty sure this solution works, but it's definitiely not the "Gradle way" to do it since it ties me to Nexus and does not use the builtin maven dependency resolution utilities.

How could I solve that without querying the Nexus API?

like image 829
Johnride Avatar asked Jul 27 '15 16:07

Johnride


People also ask

What is Mavencentral () in Gradle?

Maven Central is a popular repository hosting open source libraries for consumption by Java projects. To declare the Maven Central repository for your build add this to your script: Example 1. Adding central Maven repository. build.gradle.

Where does Gradle download dependencies from?

Gradle declares dependencies on JAR files inside your project's module_name /libs/ directory (because Gradle reads paths relative to the build.gradle file). This declares a dependency on version 12.3 of the "app-magic" library, inside the "com.example.android" namespace group.

What is JCenter in Gradle?

JCenter Android. jCenter is the public repository hosted at bintray that is free to use for open source library publishers. It is the largest repository in the world for Java and Android OSS libraries, packages and components. All the content in JCenter is served over a CDN, with a secure HTTPS connection.

What is mavenLocal?

It turns out that the mavenLocal() repository is not the Gradle dependency cache. It is a repository where you can deploy components with ./gradlew publishToMavenLocal (assuming you use the maven-publish Gradle plugin).


1 Answers

I have created a tool called the Maven Repository Provisioner that pretty much accomplishes this. You can check it out at https://github.com/simpligility/maven-repository-tools

It is used in production for exactly the purpose you want, but it also calculates and provisions all the transitive dependencies and needed parent poms. Check it out and if it doesnt fully do what you want... I take pull requests ;-)

like image 110
Manfred Moser Avatar answered Sep 18 '22 15:09

Manfred Moser