Gradle Build issue while using remote repository - gradle

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

Related

Gradle artifactory plugin not resolving JAR dependencies

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.

Unable to load Maven meta-data from private repo. Received 403: Forbidden

I'm trying append a private dependency into my project (react-native-android) via Maven. Unfortunately I'm get following error message when I try to build ./gradlew assembleDebug my project.
Error message returned as below:
> FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
> Could not resolve com.facebook.react:react-native:0.19.+.
Required by:
project :app > project :react-native-i18n
> Failed to list versions for com.facebook.react:react-native.
> Unable to load Maven meta-data from https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml.
> Could not get resource 'https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml'.
> Could not GET 'https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml'. Received status code 403 from server: Forbidden
Code example
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven { url "https://xxxPRIVATE_REPOxxx/android" }
}
dependencies {
implementation project(':react-native-i18n')
implementation 'com.android.support:support-v4:+'
implementation 'xxxPRIVATE_DEPENDENCYxxx:1.0.+'
}
I have read numerous post and research on maven and gradle's topic. Here's my finding towards my issues:
Meaning that my sequence of declaring maven by right will get the "correct/suitable" module from the first declared maven instead of the following (maven xxxPRIVATE_REPOxxx)
The order of declaration determines how Gradle will check for dependencies at runtime. If Gradle finds a module descriptor in a particular repository, it will attempt to download all of the artifacts for that module from the same repository. You can learn more about the inner workings of dependency downloads.
Returning of 403 Forbidden does not necessary mean I do not have access to the repo I'm trying to access, but also missing of resource.
Hence I made an assumption here... During the download of project dependencies, Maven loop through both maven repo (maven google & xxxPRIVATE_REPOxxx) to get the suitable lib. However when it reaches xxxPRIVATE_REPOxxx, it failed to locate maven-metadata.xml therefore result with https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml and 403 Forbidden.
My question:
Should there be a way to indicate which dependency to get from which Maven?
I was imaging something like this
implementation 'xxxPRIVATE_DEPENDENCYxxx:1.0.+' : xxxPRIVATE_REPOxxx (You know what I mean)
I have tried:
Upgrading my Android-Plugin to 3.5.0
Upgrading my Gradle version to 5.6.4
./gradlew clean and re-build after steps 1 and 2
Turns out the issue was because the react native dependencies use by 3rd party library (react-native-i18n) was too low. You can find it at react-native-i18n's build.gradle.
dependencies {
compile 'com.facebook.react:react-native:0.12.+'
}
Hence my fix to this was update the code to
compile 'com.facebook.react:react-native:+'

Is there a way to replace a Gradle dependency with another one from the filesystem?

I have a legacy project in restricted environment. We've found an issue with a third-party OSS library, forked and fixed it. However, this other tool expects the path to the artifact to be extactly as it has been hardcoded into it (it also expects it to be on classpath as a dependency). So, the dependencies look somewhate like this:
dependencies {
compile group: 'org.foo', name: 'bar', version: '1.2.3', configuration: 'runtime'
}
Where org.foo:bar:1.2.3 is the artifact that we needed to patch.
Is it possible to override this dependency with its artifact coordinates kept intact, but add something like a files section to it? If so, how? Can it be done using module substitution?
We're using an ancient version of Gradle -- 4.10.x.
While contributing the fix to the OSS library should be your end goal, you can work around the issue in the following way:
Add the patched file to a local repository under <root>/org/foo/bar/1.2.3/bar-1.2.3.jar with its matching metadata file, assuming Maven POM: <root>/org/foo/bar/1.2.3/bar-1.2.3.pom
Define this repository before other repositories in your build
repositories {
maven {
name = "localRepo"
url = "<root>"
}
// Other repositories below
}
When Gradle resolve this dependency, it will pick the one from the local repository given it has metadata and respects the repository layout.
This might require running with --refresh-dependencies to get Gradle to notice the changed dependency.
NOTE: Outside of a legacy / restricted environment, I would not recommend doing this. You are effectively shadowing an artifact in a give context, making your build brittle.

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.

Could not find dependency declared in Gradle buildscript block via Artifactory

I am using Artifactory as my artifact store, and have set this up so that it is being used as a proxy and cache for jcenter. This generally is working fine apart from for dependencies declared in the buildscript block in my main build.gradle.
My block looks like
buildscript {
repositories {
//proxies jcenter
maven {
url "https://<myArtiInstance>/artifactory/repo"
credentials {
username artifactory_reader_username
password artifactory_reader_password
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
classpath "com.android.tools.build:gradle:2.1.2"
}
}
which gives the error when running gradlew clean build (2.10)
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not find builder.jar (com.android.tools.build:builder:2.1.2).
Searched in the following locations:
https://<myArtiInstance>/artifactory/repo/com/android/tools/build/builder/2.1.2/builder-2.1.2.jar
If I wack the above url into my (authenticated) browser, I get the jar and can see its put into the arti cache.
All my other proxied dependencies seem to work so I am a bit confused as to whats going on.
At present I am wondering if this is a bug with Gradle 2.10 or something, as this used to work as I can see previous cached versions of that artifact in my arti box.
Thanks for any help or pointers :)
EDIT: If I roll back to com.android.tools.build:gradle:2.1.0 which is not in my cached repo either, build completes fine and it caches it. For some reason it does not like 2.1.2, I wonder why?!
EDIT2: Still having issues, now its taken issue with https://<myArtiInstance>/artifactory/repo/com/google/guava/guava/15.0/guava-15.0.jar which gives a similar error to the above
* What went wrong:
A problem occurred configuring root project '<name>'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not find guava.jar (com.google.guava:guava:15.0).
Searched in the following locations:
https://<myAriInstance>/artifactory/repo/com/google/guava/guava/15.0/guava-15.0.jar
This is again from a dependecency specified inside the buildscript block. Any ideas whats going on? This time is transative so I cant just swap the version. The only strange thing I notice from the error messages is that its looking for guava.jar at the url ending in guava-15.0.jar...
So it turns out inspecting the output of gradlew clean build --debug for a second time, I noticed everything was being obtained from the local ~/.gradle/cache, apart from the failing jars above. rm the cache and everything works fine, and the transitive dependencies can be obtained from the url given in the error msg. Subsequent builds which retreive from local cache work fine. Seems to me that something had corrupted the local cache (maybe partial download of complete resources i.e. pom, jar etc for the dependency) and that the gradle error msg was incorrect.
EDIT: testing just deleting the jar from cache and still compiles fine...

Resources