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

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.

Related

Gradle dependencies pom files locations on local file system

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

Gradle library including local jar as api dependency doesn't show up in consumer's classpath

In my gradle java library project, I have a dependency on a local jar file (the artifact is not published anywhere). The dependencies configuration looks like:
dependencies {
api fileTree(dir: '3rdparty', include: '*.jar')
}
When I publish my library to maven local, and then pull it in from another project, the symbols from the jar in the 3rdparty folder aren't available on the classpath, even though it's listed as an api dependency. Is this just a limitation of using jar files directly within library modules or something?
This is a well known limitation on File Dependencies. The Gradle documentation is clear on that
File dependencies are not included in the published dependency descriptor for your project. However, file dependencies are included in transitive project dependencies within the same build. This means they cannot be used outside the current build, but they can be used within the same build.
The reason is simply that those dependencies are not externally resolvable by other projects in contrast to artifacts hosted in a binary repository. Read more about this topic in the Declaring Dependencies userguide.

Can Gradle read transitive dependencies from pom.xml contained in local JAR files?

Unlike external dependencies (from Maven, Ivy, etc.) local JAR files usually do not provide a list of transitive dependencies for Gradle. Unless they theoretically do in form of files pom.xml and pom.properties in directory META-INF/maven/<groupId>/<artifactId>. As far as I understand these are the same files Maven uses to provide transitive dependencies for an artifact.
So I wonder if Gradle is somehow able to read these transitive dependencies from a local JAR file as if the local JAR was an external dependency. Only adding the local JAR as dependency seems to ignore the embedded pom.xml.
Use case: I am writing an Plugin API JAR for an internal product which should be used by our developers to develop plugins. The API JAR has some external dependencies (Hibernate Annotations in domain classes, dom4j, stuff like that) and it would be great if the developer wouldn't have to define these dependencies by himself (they could change with newer API version). I also don't want to create a fat JAR containing all dependencies because a) the size! and b) it would not contain the sources of the external dependencies.

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.)

Resources