Add Gradle cache to Sonatype Nexus - gradle

Is there an option available to add the Gradle dependency cache to Sonatype Nexus repository so that i can use that cached dependencies for my project later.

The easiest way will be writing a Gradle script, that will exact all the artifacts from Gradle cache using Gradle Artifact Query APIĀ and save them in a Maven layout. Then you can import them to Nexus or Artifactory.

Related

When does gradle store in .m2 and when in cache?

In which scenario will gradle store artifacts in the directory .m2 and in which scenario will it store them in gradle\caches?
I am trying to resolve my issue wherein I have a dependency within my local build
Gradle will read from your local maven repository only when you declare it as a valid repository:
repositories {
mavenLocal()
}
Gradle will write to your local maven repository only when you publish artifacts and tell it to publish to the local maven repo.
If you are using the maven plugin, when executing the task install
If you are using the maven-publish plugin, when executing the task publishToMavenLocal
Gradle will use its own internal cache for all resolved dependencies, including ones coming from the local maven repository.
For example, if you use a dependency org:foo:1.0 from your maven local repository, the metadata and artifact will be copied to the Gradle cache on first resolution. From then on, the dependency will be resolved from the Gradle cache.
However, if the dependency is changing, such as when using a -SNAPSHOT version, the Gradle cache will by default keep the last one resolved for 24h. After which it will perform a new resolution, hitting again the local maven repository in this example.
See the documentation for controlling that cache duration for dynamic and/or changing dependencies.

How to download snapshots from Nexus using Gradle build?

I am able to download the snapshots in Nexus Repo using Maven but not with Gradle?
Isn't Gradle compatible to get snapshots?

Maven repository usage to download artifacts

I have added a repository to download artifacts and I have seen maven using that repository to download artifacts, but only for particular artifacts of that repository maven tries to download from mvn central repository. When I chek that artifact on added repository it's available. What could be the issue ? In which situations maven tries to download from central repository ?
Specific issues is highlighted in ,
Magnolia Demo project mvn build failed due to not able to fetch magnolia-setproperty-maven-plugin
All the Maven dependencies are first downloaded from your local repository, then if they are not found, Maven will try in any remote repository that you define in your POM file or the settings.xml and for last it will try to download from Maven Central.

Automatically download missing artifacts if missing in Artifactory

I'm using Jfrog Artifactory to contain artifacts. I'm building with Maven. Is there a way to configure Maven to automatically download missing artifacts, artifacts that are not in the Artifactory repo.
Example:
org.maven.framework-2.5.0 is downloaded from Artifactory since it exists in the Artifactory.
org.maven.anotherframework-2.2.2 doesn't exists in Artifacotry. How to set maven to get from internet?
Is it common to use Artifactory this way?
You should configure Artifactory to fetch missing artifacts from the Internet, not Maven.
Artifactory can (and should) be used as a proxy:
It already comes with set a pre-configured popular remote repositories and you can add new ones.
So, if Maven fails on unresolved dependency, find a repository that has it, add it to Artifactory as remote repository, retry the build. If you can't find any repository that has it, you can upload the jar directly to Artifactory and retry the build.

Declaring a Maven project dependecy on artefact in an Ivy repo

I have a Maven 2 project and now need to declare a dependency on artefacts which are kept in an Ivy repository.
Is this possible and if so how?
Maven is a rather opinionated framework, so only supports Maven repositories.
Do you have any control over the ivy repository? The best solution would be to migrate it's contents over to a Maven repository manager like Nexus (Artifactory, Apache Archiva are other options).
There are lots of advantages to having a repository manager:
Support for all build clients, Maven, Ivy, Gradle, etc
Ability to search for artifacts
..
I ended up migrating this project to Gradle. By default Gradle uses the same project layout as Maven, so the migration was very simple.
Gradle allows you to declare dependencies across many types of repositories:
Maven
Ivy
Flat file
So you could have some dependencies in a Maven repo, others in an Ivy repo and others in a project lib directory (shock, horror!).
Highly recommended.
Try the Ivy Maven Plugin:
https://github.com/remis-thoughts/ivy-maven-plugin
"A plugin to add apache Ivy dependencies to a Maven project. This is a fork of Evgeny Goldin's Ivy Maven Plugin that fixes support for transitive dependencies."
(Note that the early comments below refer to Evgeny Goldin's Ivy Maven Plugin - looks like this fork fixes the problem I was having).

Resources