Reputation: 1711
Why does gradle not searching for dependency in ALL defined maven repos?
Repos block is defined:
repositories {
maven {
name = 'JBoss.org Maven repository'
url 'https://repository.jboss.org/nexus/content/groups/public'
}
maven {
name = 'spring-milestones'
url 'http://repo.springsource.org/libs-milestone/'
}
mavenCentral()
}
(Assuming I got somewhere in the subproject net.sf.json-lib:json-lib:2.2.1
) I receive:
* What went wrong:
Could not resolve all dependencies for configuration ':myproject:compileClasspath'.
> Could not find json-lib.jar (net.sf.json-lib:json-lib:2.2.1).
Searched in the following locations:
http://repo.springsource.org/libs-milestone/net/sf/json-lib/json-lib/2.2.1/json-lib-2.2.1.jar
Why the only one search-location? The json-lib
clearly exists in mavenCentral()
.
Is there any way to profile that, or debug somehow?
P.S. I could fix that if I move mavenCentral()
up one position in the list of repos, but that will break another subproject dependency-resolution by the very same reason -- something from "spring" repo does not exist in mavenCentral()
.
Upvotes: 11
Views: 7616
Reputation: 1452
What works for me when this happens is going to my gradle cache in /Users/<username/.gradle/caches and searching for the dependency:
tree -f | grep exampleLib
│ │ │ ├── ./modules-2/files-2.1/com.example/exampleLib
│ │ │ │ ├── ./modules-2/files-2.1/com.example/exampleLib/0.0.1
│ │ │ │ │ ├── ./modules-2/files-2.1/com.example/exampleLib/0.0.1/1231161235123475345345235
│ │ │ │ │ │ └── ./modules-2/files-2.1/com.example
I use tree
command but you can use find
also. In this example my project is names exampleLib
and has the the com.example
group ID.
Then just delete the directory containing the dependency.
rm -f -R ./modules-2/files-2.1/com.example
Then click refresh in IntelliJ (if you use it), and do a gradle clean build
.
Upvotes: 1
Reputation: 89
In my case, everything was fine with the dependency, but still gradle was not able to locate the artifact from one of the 5 repositories I had. What helped me was --refresh-dependencies option
i.e., gradle clean build --refresh-dependencies
I understand that I was not able to locate the exact problem, but this gave me a quick resolution. Note that all the dependencies will be downloaded again, which could take time
My gradle version is 6.5.1
Upvotes: 3
Reputation: 1711
In fact, gradle searches for all maven repos. You can see that JBoss repo does not contain 2.2.1 version of json-lib, so, it skips to the next one (spring repo).
Spring repo has 2.2.1, but, the issue here is that the artifact has distribution specified, so, you just need to fix the dependency:
compile 'net.sf.json-lib:json-lib:2.2.1:jdk15'
Upvotes: 3