Gradle artifactory plugin not resolving JAR dependencies - gradle

I am upgrading my build to Gradle 7.4.2 running with Java 11 and use Artifactory as my repository. I am using the latest Gradle Artifactory Plugin and my builds are failing to resolve JAR dependencies now.
In Artifactory I'm using a virtual repository to resolve dependencies like Apache Commons Text as well as my own local collection of JARs that I've deployed to a separate Artifactory repository that is connected to the virtual repository.
My build was resolving my JAR dependencies fine under Gradle 5.6.4/Java8. Now my build fails with errors like this.
Resource missing. [HTTP GET: https://artifactory.myco.com:443/artifactory/collective-gradle-virtual/com/myco/a/myjni/2.5-AABBCC/myjni-2.5-AABBCC.pom]
Resource missing. [HTTP GET: https://artifactory.myco.com:443/artifactory/collective-gradle-virtual/com.myco.a/myjni/ivy-2.5-AABBCC.xml]
The final build error message said something similar:
> Could not find myco.com.a:myjni:2.5-AABBCC.
Searched in the following locations:
- https://artifactory.myco.com:443/artifactory/collective-gradle-virtual/com/myco/a/myjni/2.5-PH44157/myjni:2.5-AABBCC.pom
- https://artifactory.myco.com:443/artifactory/collective-gradle-virtual/com.myco.a/myjni/ivy-2.5-AABBCC.xml
Required by:
project :MyJAR
Is there some change between Gradle/the Gradle Artifactory Plugin/Java 11 such that the build can no longer resolve JAR artifacts?
I even tried creating a myjni-2.5-AABBCC.pom file and deployed it to the same path as the JAR. That fails too because the repository has the JAR and POM in com.myco.a and the resolver is looking for it in com/myco/a.
I also changed my dependencies to append #jar at the end in the hopes that would change the resolver behavior. It did not.
My dependency looks like this:
dependencies {
implementation 'com.myco.a:myjni:2.5-AABBCC#jar'
}
My artifactory block is this:
artifactory {
contextUrl = "https://artifactory.myco.com:443/artifactory"
resolve {
repository {
repoKey = 'collective-gradle-virtual'
username = "${artifactoryUser}"
password = "${artifactoryKey}"
maven = true
}
}
}
Update 1
I discovered that even though my existing setup worked fine before the upgrade, for some reason now, it requires a POM file to exist with the actual JAR. I also suspect that the use of dots in the group name is causing problems with locating the POM file. So I'm renaming those groups to not have dots.
UPdate 2
I restructured my repository to change the dotted group name in the repository to a maven-style directory tree and added a POM for each dependency. Now the dependencies resolve, but I don't understand why the behavior changed when I upgraded Java, Gradle and the Gradle Artifactory Plugin.

Related

In gradle, a maven artifact without a pom file works from jcenter but not mavenCentral

I have a Java project using gradle that uses some very old dependencies. One of them has a transitive dependency that works fine with jcenter() but now fails when I try to migrate to mavenCentral(). The artifact exists in Maven Central but has no pom file. Gradle gives me an error like this:
> Could not resolve all files for configuration ':myproject:compileClasspath'.
> Could not find woodstox:wstx-asl:3.2.7.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/woodstox/wstx-asl/3.2.7/wstx-asl-3.2.7.pom
Any attempt on my part to browse the jcenter repository returns a 403 Forbidden so I can't tell if the pom file exists there but somehow Gradle is able to build the project using jcenter().
That leaves me with a few questions:
Are pom files required in (very old) maven artifacts?
How does gradle gain access to https://jcenter.bintray.com/?
Is there any way to find out if the jcenter artifact has a pom file?
If it doesn't have a pom file, why does gradle work with jcenter() but fails with mavenCentral?
Thanks in advance for any help!

Getting oracle JDBC jar from from Nexus with gradle

I seen this question but nothing seemed to help. I will do my best to make the answer better and hopefully show a solution.
In my build.gradle under dependencies I have:
compile files('oracle/ojdbc7-12.1.0.2.jar') where I was manually placing the jar in the directory.
What I am doing now is trying to pull it from nuxus.
I my local gradle.properties I added my username and password but it pulls ALL dependencies and is not able to get them all from nexus and fails. I want to just pull one jar (jbdc) with gradle build.
Error is here:
> Configure project :api
init.gradle/NexusRepositoryPlugin: MavenRepo at https://repo.maven.apache.org/maven2/ removed.
init.gradle/NexusRepositoryPlugin: __plugin_repository__Gradle Central Plugin Repository kept (not a Maven repository).
init.gradle/NexusRepositoryPlugin: MavenRepo at https://repo.maven.apache.org/maven2/ removed.
init.gradle/NexusRepositoryPlugin: BintrayJCenter at https://jcenter.bintray.com/ removed.
* What went wrong:
Could not resolve all dependencies for configuration ':api:detachedConfiguration1'.
> Could not resolve org.springframework.boot:spring-boot-dependencies:2.0.1.RELEASE.
Required by:
project :api
> Could not resolve org.springframework.boot:spring-boot-dependencies:2.0.1.RELEASE.
Advice?
My understanding of the question indicates that you are replacing the public repository declaration with a private one that contains only that JDBC jar.
You should instead leave the public repository declaration and add the private one. Gradle will then search for the JDBC jar in both the first time and retrieve it.

Force Gradle To Resolve Snapshot Dependencies From Different Repo

In my build.gradle for a Java project, I have a list of Maven repositories I am pointing to for dependency resolution, as follows:
repositories {
maven {
url "https://artifactory.myco.com/artifactory/maven-us-east-1-local"
}
maven {
url "https://artifactory.myco.com/artifactory/maven_snapshots-us-east-1-local"
}
mavenCentral() }
It looks like the snapshots repo above barfs during resolution when gradle tries to see if a non-snapshot dependency lives there, as it goes through and contacts each repo in order. In artifactory it has been configured with a policy and it sends back a 409 conflict when it gets asked if it has a non-snapshot dependency. This is what I get:
./gradlew build
.
.
.
FAILURE: Build failed with an exception.
What went wrong:
Could not resolve all dependencies for configuration > 'com.myco.project:pgs_common:compile'.
Could not resolve mydep:mydep:1.0.9.
Required by:
com.myco.project:pgs_common:1.28.0-SNAPSHOT
Could not resolve mydep:mydep:1.0.9
Could not get resource 'https://artifactory.myco.com/artifactory/maven_snapshots-us-east-1-local/mydep/mydep/1.0.9/mydep-1.0.9.pom'.
Could not GET > 'https://artifactory.myco.com/artifactory/maven_snapshots-us-east-1-local/mydep/mydep/1.0.9/mydep-1.0.9.pom'. Received status code 409 from server: Conflict
Is there a way in gradle to tell it to not bother contacting that repo for non-snapshot dependencies? In Maven you can add extra properties in a repository declaration telling Maven whether it allows release dependencies, snapshot dependencies, or both (the default).
Thanks.
I have similar issues with Gradle 4.x and 5.x, the workaround is to use Gradle 2.x.
By using Gradle 2.x does not stop Gradle search non-snapshot libs from release repository, but at least Gradle can find decency.

Gradle Build issue while using remote repository

Issues which I am facing are related to gradle build. I would like to explain what I am doing.
I created a remote repository on a remote server and I am able to access it from browser (the shared folder under which I have kept some dependency Jars).
Now I want to use that remote repository in my build.gradle (like a remote maven repository) and so I added snippet like this:
apply plugin: 'maven'
repositories{
maven {
//URL of the remote repository
url "http://IP:Port/SharedPath"
}
}
dependencies {
//Dependencies which are there in remote repository.
compile group: "GroupName", name: "DependencyName", version: "Version"
compile group: "GroupName1", name: "DependencyName1", version: ""
}
When I am running gradle build, I am getting error message like this:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not find :cachedb.jar:.
Searched in the following locations:
http://IP:Port/SharedPath/GroupName/DependencyName/Version/DependencyName-Version.pom
http://IP:Port/SharedPath/GroupName/DependencyName/Version/DependencyName-Version.jar
Required by:
:site-export-tool:unspecified
> Could not find :cachejdbc:.
Searched in the following locations:
http://IP:Port/SharedPath/GroupName1/DependencyName1//DependencyName1-.pom
http://IP:Port/SharedPath/GroupName1/DependencyName1//DependencyName1-.jar
Required by:
:site-export-tool:unspecified
I don't understand why it is searching the file at the path: url / GroupName / DependencyName / Version / DependencyName-Version.jar
While it should check for the jar at the path in URL only and not under some folder structure on the name of GroupName and DependencyName and so on... or simply say, I dont want to pass GroupName (it is possible?)
Please NOTE: I tried this also:
compile files ('lib/DependencyName-Version.jar',
'lib/DependencyName1.jar')
Please be notified that, When I am keeping those dependencies in my local system and defining them in flatDir, I am NOT facing any issue in that case.
I am trying to use remote repository because we in our organization want to use a centralized location.
Please let me know if I need to do anything with gradle configuration or gradle version which I am using (gradle 2.13) or anything in build.gradle only, I dont understand what is wrong which I am doing here. Stuck from past 2 days :-(
Thanks a ton in Advance!
This is because gradle expects standard maven repository structure when you use maven {url ".."}, which is
/$groupId[0]/../${groupId[n]/$artifactId/$version/$artifactId-$version.$extension
See https://cwiki.apache.org/confluence/display/MAVENOLD/Repository+Layout+-+Final
Either follow that structure or you can try using Ivy repository with custom layout.
https://docs.gradle.org/current/userguide/dependency_management.html#sec:defining_custom_pattern_layout_for_an_ivy_repository

How does Gradle/Ivy read a Nexus repo acting as a Maven mirror?

How does Ivy read a Nexus repo acting as a Maven mirror?
I was thinking about using Gradle as my build system, and Gradle is built from Ant+Ivy (using Groovy). I have a Nexus repository on my local network that acts as a "mirror". In order for me to build my projects, I put a "mirror" entry in my .m2\settings.xml config file. I am able to build my Maven projects just fine but Gradle does not read the .m2 config and so my Gradle projects wont build.
I do not know how to configure Gradle to use the nexus repo as a mirror. Can anyone explain this or give me some hints? I suspect it has something to do with usage of a ivysettings.xml file maybe? This post implies that Gradle DOES in fact read the Maven config but I do not experience this.
I'm using Gradle with a Nexus repo and a Maven proxy and I did not have to modify any of those xml files. I just installed Nexus, created a user with a password through the admin UI, and added this config in my gradle init script (e.g. ${USER_HOME}/.gradle/init.gradle):
allprojects {
repositories {
// Third party dependencies are fetched from MavenCental through a Nexus proxy repository
maven {
credentials {
username 'some_username'
password 'some_password'
}
url 'http://dev.primalogik.com/nexus/content/groups/public/'
}
}
dependencies {
// Example of a compile time dependency
compile group: 'com.google.gwt', name: 'gwt-dev', version: '2.5.1'
...
}
}
The following answer describes how to configure a Maven repository manager in ivy:
Use public maven repository with ivy
I'm uncertain whether this actually helps with a Gradle build (I thought Gradle had stopped using ivy).
Update
Gradle documentation on configuring repositories:
http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:maven_repo

Resources