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.jar
file 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?
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.
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.
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.
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).
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 ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With