Gradle find wrong maven repository url in eclipse - java

this is my build.gradle
repositories {
mavenCentral()
maven{url 'http://example.com/repository/maven-public/'}
}
dependencies {
compile group: 'com.example', name: 'example-commlib', version: '1.0'
}
and the link http://example.com/repository/maven-public/ is build from Nexus Repository Manager which can accessable.
and when I click Refresh Gradle Project in eclipse.
I can see the link is point to
https://repo.maven.apache.org/..../example-commlib-1.0.pom
I think the right url is
http://example.com/repository/maven-public/.../example-commlib-1.0.pom
I've check the gradle setting and maven setting in eclipse. It seems fine.
So what's the problem?

Do you have other dependencies on this project? It is possible that the "pom.xml" file of one of the packages you are pulling references example-commlib as a dependency and has the Apache Maven URL hardcoded, and resolves the URL beforehand. You can use gradle dependencies to show the dependency tree and find which version is affected. The answers in this post have suggestions on how to force a specific dependency as well: How can I force Gradle to set the same version for two dependencies?

Related

gradle can't resolve nexus dependency

I have a dependency I'd like to include from a local nexus. I've seen several related problems that all say to do something like
apply plugin: "java"
apply plugin: "maven"
repositories {
maven {
url "http://my.url.com/"
}
}
dependencies {
compile "name:id:version"
}
I can access the nexus fine via web but when I try the above, I end up with a error message
Could not resolve: name:id:version
Any help would be greatly appreciated.
I found my problem. There were transitive dependencies I didn't catch as I was initially building from Eclipse without the --stacktrace option. I modified the build script such that
compile("name:id:version") {
exclude group: "another-name", module: "its-module"
// other dependencies to exclude ...
}
If by local repository you mean your local computer repository, then to ask Gradle to lookup dependencies from the local maven repository you should explicitly tell him to do so like this:
repositories {
mavenLocal()
}
Gradle is not like maven and is not using the local repository of the maven to cache downloaded artifacts. From the Gradle points of view, the local maven repository is also like other repositories.

Gradle could not find retrofit dependencies

I need some retrofit2 dependencies for my java project.
In build.gradle additional repositories are declared:
repositories
{
jcenter()
mavenCentral()
mavenLocal()
}
In dependencies section I declared:
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
So Gradle could not find them.
I used project-report plugin to analyze dependency tree. I got next report:
Interesting thing that before I used 2.0.2 versions for retrofit libraries and Gradle found them.
Any help will be appreciated.
Gradle version 2.12
If using IntelliJ you can include plugin idea or include plugin eclipse, which gives you an option to run gradle idea or gradle eclipseClasspath tasks and refresh the project with updated/freshly added dependencies.
IDE's are not yet ideal supporting gradle.

Gradle unable to resolve Sonatype Nexus dependency in IntelliJ

I am using Gradle in a new IntelliJ project. We have an internal Sonatype Nexus repository and I have declared that in build.gradle. I also added the dependency to the build script.
group 'com.companyName'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven{
url 'http://host:port/nexus/content/repositories/releases'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'com.companyName', name:'abc', version: '2.2.7'
}
As you can tell this is a brand new project. IntelliJ will build the project but wont resolve the external dependency. When I look in the Gradle projects view in IntelliJ there is a red squiggly line under the dependency and it says Unable to resolve dependency. I know the dependency exists and I can use it in Maven projects.
I've search around without any solution, tried all different settings in the intelliJ project also. Any ideas?
From discussion comments on the original post:
There seem some caches be corrupt.
Delete the .gradle folder in your project and ~/.gradle/caches, then try to resolve the dependencies again.
I had a similar problem with IntelliJ 2017.1 connecting to Artifactory. I opened a Terminal, ran "./gradlew tasks" and, as a side-effect, the dependency was downloaded.
Issues like unable to resolve dependencies(even after checking that there are no typos) could be because of firewall settings.
Check with your security department on how to fix it.
In some organizations, they've local mirror. In gradle.properties you'll have to give that path in distributionUrl
Also in build.gradle use corresponding path in repositories.

Gradle won't resolve dependency (Maven will)

My project has dependencies configured through gradle. I would like to add the following dependency:
compile group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', version: '2.3.1'
Which can be found in the following repository (which I have added to my build.gradle):
maven {
url "http://maven.restlet.org"
}
However when I do that I get the following error:
Could not find org.restlet.jse:org.restlet.lib.swagger-models:1.5.0-SNAPSHOT.
http://maven.restlet.org/org/restlet/jse/org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/maven-metadata.xml
http://maven.restlet.org/org/restlet/jse/org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/org.restlet.lib.swagger-models-1.5.0-null-null.pom
http://maven.restlet.org/org/restlet/jse/org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/org.restlet.lib.swagger-models-1.5.0-null-null.jar
Required by: org.restlet.jse:org.restlet.ext.apispark:2.3.1
I can see that the jar is in fact in the repository however Gradle is not looking for it in the right location for reasons unknown to me. Why is it not using the version in the filename but rather 1.5.0-null-null.
I have made a made a Maven project with the same dependency defined in the pom.xml which works.
Link to working pom.xml that has same dependency
How can this issue be resolved? I'm at this point also interesting in more manual solutions :) Thank you.
Diagnosis
It seems to be related to snapshot "uniqueness". For information on Maven repositories, snapshots artifacts can be deployed "unique" or "non-unique".
Unique snapshots: Each time you deploy a snapshot, it is tagged with a timestamp and a buildNumber, these timestamp and buildNumber are written in the maven-metadata.xml file and they are appended to its name that ends up like: artifactName-version-timestamp-buildNumber.jar.
Non-unique snapshots: Each time you deploy a snapshot it overwrites the previous version, his name ends up like: artifactName-version.jar.
It is recommended to use unique snapshot as one can refer precisely to one version of the artifact if needed.
The problem is that "http://maven.restlet.org" seems to use non-unique snapshots and sadly, gradle seems to have problems to deal with non-unique snapshots: https://issues.gradle.org/browse/GRADLE-3164.
If you look at http://maven.restlet.com/org/restlet/jse/org.restlet.lib.org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/maven-metadata.xml you can clearly see null in timestamp and buildNumber tags:
<metadata>
[...]
<versioning>
<snapshot>
<timestamp>null</timestamp>
<buildNumber>null</buildNumber>
</snapshot>
<lastUpdated>null</lastUpdated>
</versioning>
</metadata>
I think that's where the "null-null" comes from.
Solution 1 - flatDir
To deal with it you can manually download the artifact, put it in a directory, for example "lib" and create a flatDir repository:
repositories {
[...]
flatDir {
dirs 'lib'
}
[...]
}
It's not an ideal solution, but it works.
Solution 2 - jcenter repository
Suggested by Opal
Add the jcenter repository that contains your missing dependency and that Gradle handles well.
Since Gradle 1.7 you can simply define it with:
repositories {
[...]
jcenter()
[...]
}
It seems that you need other repositories to download all the dependencies. Probably maven handle this transparently. The following script downloads all dependencies successfully when cp task is run:
apply plugin: 'java'
configurations {
lol
}
repositories {
jcenter()
mavenCentral()
maven {
url "http://maven.restlet.org"
}
maven {
url "https://repository.mulesoft.org/nexus/content/repositories/public/"
}
}
dependencies {
lol group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', version: '2.3.1'
}
task cp(type: Copy) {
from configurations.lol
into 'deps'
}

Maven dependency in a Gradle project

I'm developing a project with gradle. My build file is almost empty so far:
apply plugin: 'java'
apply plugin: 'eclipse'
version = '0.1'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
}
My project depends on a Maven project. Precisely this project: http://git.eclipse.org/c/bpmn2/tree/org.eclipse.bpmn2
I've cloned this project into my workspace, but I don't know the best way to declare the dependency in my build.gradle file. This is what I've done so far:
dependencies {
compile files ("C:/path/to/org.eclipse.bpmn2-0.7.0-SNAPSHOT.jar")
}
But this way I have to manually build the maven project. Does somebody know a better way of doing this dependency management?
I'm using Eclipse Gradle Integration and I've noticed an interesting eclipse project property:
Gradle - Dependency Management
[x] Remap Jars to maven projects (requires Gradle 1.1 and m2e)
This seems to do what I need. But I don't know how to use this feature...
Thanks in advance.
If the Maven project is not available in any Maven repo, Gradle can't find it anywhere, so you'll have to build it. I would at least mvn install it, and tell Gradle to look for artifacts in your local Maven repo rather than in a specific directory, using
repositories {
mavenLocal()
}
The eclipse-integration-gradle plugin replaces the mavenLocal() jar dependency with a Eclipse project dependency. This is the easiest way I've found so far. See: http://forum.springsource.org/showthread.php?139634-How-to-use-quot-remap-Jars-to-maven-projects-quot-feature

Categories