0

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?

mfunaro
  • 574
  • 6
  • 23
  • What does the output say if you call gradle from the commandline with the `dependencies` task. Is it able to resolve the dependency or not? – Vampire Oct 06 '16 at 14:17
  • Have you rebuilt the project and made sure the dependency was downloaded into the project? Check to see if you can find it under the external libraries. This happened to me once and doing a build from the project didn't work so I re-imported the project to intelliJ by double clicking on the build.gradle file and that added the dependencies correctly. – Brion Oct 06 '16 at 14:20
  • Usually, this is either a typo in group/artifact/version or your Maven url is not correct. – J Fabian Meier Oct 06 '16 at 14:20
  • @Vampire, I can run it from the command line but the dependencies are not resolved. There is no typo I can see. – mfunaro Oct 06 '16 at 14:33
  • Well, then it is not an IntelliJ issue and no setting in IntelliJ will help you. If you access with your browser the URL `http://host:port/nexus/content/repositories/releases/com/companyName/abc/2.2.7/abc-2.2.7.jar`, do you download the JAR? If not, something is wrong with either your nexus or your config – Vampire Oct 06 '16 at 14:47
  • Well I am utterly baffled. In desperation I deleted the project, recreated it with with a few other plugins applied and all of a sudden it resolved the dependency. I then pared down the build.gradle to what I originally posted and it is still able to resolve the dependency. Thanks @Vampire and others for lending an ear. I wish I knew the actual cause of the issue though. – mfunaro Oct 06 '16 at 15:05
  • Hm, strange. I'll make an answer out of this, so can add a green check mark. Strange though. Maybe adding `--refresh-dependencies` once to the gradle call would have helped, or deleting the caches. Those would have been my next suggestions after you successfully checked the URL. – Vampire Oct 06 '16 at 15:08

3 Answers3

1

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.

Vampire
  • 35,631
  • 4
  • 76
  • 102
1

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.

1

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.

Aman Sehgal
  • 546
  • 4
  • 13