Gradle dependencies pom files locations on local file system - gradle

I understand that Gradle stores project dependencies cache in ~/.gradle/caches/modules-2 for the actual jar files. However, does Gradle also store .pom anywhere locally? Also, if I previously downloaded same dependencies through Maven (stored in ~/.m2/repositories) would Gradle reuse them automatically? In Maven, pomfiles are downloaded along side jars.
If POMs are not downloaded as part of gradle build, what's the best way to programmatically get the POMs for package metadata?

Gradle seems to use a local cache and not a repository, unless depending on mavenLoacal().
You could use the API which mavenCentral() provides:
https://central.sonatype.org/search/rest-api-guide

Related

How gradle get all the dependencies of a third party library?

In my springboot application (kotlin+gradle) I'm trying to use one of my libraries stored in Nexus. This nexus-library needs some dependencies from AWS sdk and other repositories.
Must I configure gradle.build.kts with all the repositories needed to fetch all these extra dependencies?, does it know gradle where are all these dependencies directly from the Jar?, or.....how is this done?
Gradle will use the POM file for the dependency to work out any transitive dependencies, and will attempt to retrieve them from your configured repository. If they are not available directly from there then you'll need to add additional repositories into your Gradle configuration to tell Gradle where it can search for these dependencies.
For Gradle version 6, Gradle will try to resolve a dependency in the following order
Gradle module metadata (a JSON file with .module extention)
Maven metadata (.pom file) or Ivy metadata (.ivy file) depending on Maven or Ivy repository respectively
The artifact(E.g., jar) itself if no metadata is found. This has been disabled but can be enabled through an additional configuration.
See Gradle documentation for more information.

Why gradle not creating local repository and downloading same dependencies for every project

I'm using Gradle with Java Project in IntelliJ Idea.
I see that Gradle downloading dependencies for first time on opening project.
But there is another project with same dependencies then also it's re-downloading those libs. why?
Why doesn't it maintain Maven like local repository even after configured?
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
How can Gradle maintain local repository and next it should first check local repo and go for download if no matching dependencies found?
With that piece of code you instruct gradle to look at the local maven repository, then at the central maven repository and last in JCenter when looking for dependencies. The first one it finds your dependency it takes it from.
It does not instruct Gradle to put resolved dependencies to the local maven repository though. This is e. g. helpful if you have two projects in two separate builds, one depends on the other and you install the first dependency to the local maven repository with the respective Gradle task and then build the second one, depending on the version you just built and installed.
Gradle has a resolution cache though in ~/.gradle/caches/modules-2/files-2.1/ where it caches all downloaded dependencies and also reuses this from different builds.

Download dependencies from url and extract to a folder using gradle

I am a gradle newbie. I see that gradle supports maven and ivy out of the box, however I have a need where the dependency for a java project is to be downloaded from a url. The dependencies are actually jar files which are zipped, I also need it to be extracted.

what's the difference between .ivy2 and .m2

Previously I am using sbt, and looks like it put jar under .ivy2. And then I used gradle, I have thought it also put jar under .ivy2, but the following link told me I need to delete corrupted package from .m2. So gridle is using .m2 and can not use ivy2?
spring boot mvc: failed after following the sample
Ivy, Maven and Gradle each have their own dependency cache in ~/.ivy2/cache, ~/.m2/repository, and ~/.gradle/caches, respectively. Gradle will only use Maven's dependency cache (known as the local Maven repository) if mavenLocal() is declared as a repository in the build script. This should only be done if the Gradle build needs to consume artifacts produced by a local Maven build. (There aren't any efficiency gains; in fact declaring mavenLocal() will make the build slower and less reliable.)

How to install a Maven/Gradle project along with all its dependencies to a local repository?

I have a Gradle project that depends on several open-source projects up on Maven Central. I'd like to install the project – along with all its direct and transitive dependencies – to my local maven repository, so that I could later zip it all up and put it on offline machines.
How do I do it with Gradle/Maven?
mvn dependency:get plugin will fetch the artifact with all dependencies to the local repository.
I had also developed a plugin to install remote artifacts to a local machine.
If you want to later ZIP up your project w/ dependencies and move them to a different machine, you could try Maven's appassembler plugin. It collects all dependencies and creates a launcher, all in the target folder, ready for deployment.
But note, this, by default, creates a flat directory structure with all dependencies, it doesn't preserve the Maven format. It also has the option to create a repository.

Resources