External Dependencies not pulled after clearing gradle cache


(Natty deor) #1

This is a boiler plate gradle file from Spring.io.
I added few dependencies like okhttp and following that i had add gson dependency to prettify json. but the last dependencies never appears in the project compilation in IntelliJ. I can’t use the library. Infact can’t use any latest library. However i see them being pulled when i run the commands below. I have tried clearing the gradle cache etc.

rm -rf $HOME/.gradle/caches/
./gradlew clean build

buildscript {
ext {
springBootVersion = ‘1.5.3.RELEASE’
}
repositories {
mavenCentral()
}
dependencies {
classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”)
}
}

apply plugin: 'java’
apply plugin: 'idea’
apply plugin: ‘org.springframework.boot’

jar{
baseName = 'xxxxx-rest-service’
version = ‘0.1.0’
}

version = '0.0.1-SNAPSHOT’
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile(‘com.google.code.gson:gson:2.2.4’)
compile(‘org.apache.cxf:cxf-spring-boot-starter-jaxrs:3.1.11’)
compile (‘com.squareup.okhttp3:okhttp:3.8.0’)
//compile(‘org.springframework.boot:spring-boot-starter-data-gemfire’)
compile(‘org.springframework.boot:spring-boot-starter-jersey’)
compile(‘org.springframework.kafka:spring-kafka’)
compile(‘org.springframework.boot:spring-boot-starter-web’)
runtime(‘org.springframework.boot:spring-boot-devtools’)
runtime(‘org.postgresql:postgresql’)
testCompile(‘org.springframework.boot:spring-boot-starter-test’)
}

I wonder if i have a wrong dependency specified or a bug in the gradle version. Also i imagine this is simple yet blocking me from moving forward. It compiles but can’t see the external libraries. Hence cant be used. Any directions or suggestions or correction much appreciated. Please let me know if i need to just step down to a different gradle version.


(Chris Doré) #2

How are you opening the project in IntelliJ?

Are you using ./gradlew idea to generate the project files and then opening that, or are you using IntelliJ’s built in Gradle support to open the Gradle project directly?


(Natty deor) #3

Thanks Chris,
I use Idea . on commandline(iterm) to open a project. I keep it open add code/ dependencies, then do a gradle build on commandline. I don’t think i used any built in Gradle support to open the Gradle project directly ? Anything out of place ? Would that route make a difference ? Looking for your response.


(Chris Doré) #4

Typically you’d do one of two things:

  1. ./gradlew idea will download the dependencies and generate the corresponding IntelliJ project data. That’s what the idea plugin does. Deleting the Gradle cache would invalidate the generated project data since the referenced files would no longer exist.
  2. Open the project in IntelliJ as a Gradle project, which will use the Gradle Tooling API to configure everything (including downloading of the dependencies). Note: I’m assuming you’re using a version of IntelliJ that is relatively recent (the last year or so).

Using IntelliJ 2017.1.4, idea . brings me to IntelliJ’s “Import Project from Gradle” screen, which is option 2 above.


(Natty deor) #5

I did do “./gradlew idea.” and the response was

I did open the IntelliJ and clicked on rebuilding the project( which i believe would utilize the gradle tooling api to configure.) But still couldn’t import the library. Clearly, I am able to download/pull external libraries however i don’t see them available for import in intelliJ. Lastly i was just downloading the latest GSON library and since then i couldn’t import any library on any of the projects however i do see them being pulled into cache when i do gradle build. Weird isn’t it ?

Also in the project.iml , i see that the following files were cached however not available in the intellij classes to import the library…
Just clueless again.

The following is a project *.iml file generated after building the project using Intellij.
For the purpose of neat display, i have removed the closing tags.

<orderEntry type=“module-library” scope=“RUNTIME”
<library
<CLASSES
<root url=“jar:///Users/Natty/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.2.4/a60a5e993c98c864010053cb901b7eab25306568/gson-2.2.4.jar!/”/
</CLASSES
<JAVADOC/
<SOURCES
<root url=“jar:///Users/Natty/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.2.4/a6dc5db8a12928e583bd3f23e72d3ab611ecd58f/gson-2.2.4-sources.jar!/”/
</SOURCES
</library
</orderEntry

Any lateral thoughts will be of great value. I am in sort of a blocker since i am unable to import the external dependencies however they are downloaded to cache.

Thank you,
Natty


(Chris Doré) #6

Ok, I think I might see what you’re seeing.

Using your example build.gradle file, if I use the idea task in Gradle 3.5 to generate the IntelliJ project files, it appears to put the dependencies in the incorrect scopes. For example, gson ends up in runtime and not compile. If I use Gradle 2.14 then the IntelliJ files look more correct.

If I do not use the idea task and instead just import the project using IntelliJ’s Gradle support, then the dependencies appear correctly, regardless of whether I use Gradle 2.14 or 3.5.

Since I never use the idea task/plugin (IntelliJ’s Gradle support does everything I need), I’m not super familiar with it, but this does seem like it could possibly be a bug.


(Natty deor) #7

Chris,

Thanks for looking into it.
Thats an interesting find. I am curious about the route in which you changed the Gradle version in IntelliJ that made it work for earlier versions. I updated the gradle wrapper version to say 2.12 (./gradlew wrapper --gradle-version 2.12) and unfortunately seem to produce the same result. I repeated on clearing the cache like i did earlier and reran ./gradlew idea and ./gradlew clean build etc.

Also i have a question on gradle version selection.
Like, did you select the local gradle distribution and use default gradle wrapper ?.

Thank you for the response. Also if it’s a bug, wondering how do i escalate it ?. I am sort of stuck. I noticed this ever since i created a wrapper or after in upgraded my gradle version in this new machine. Regardless the native spring boot dependencies are pulled in with no additional effort. Last try would be try on a different development machine.

Please let me know if my trails seem to be an anamoly.

Sincerely,
Natty


(Chris Doré) #8

Bugs are raised/tracked in GitHub Issues.


(Natty deor) #9

Chris,

I think if i just import the project into intellij from the build.gradle as opposed to doing “idea .” in the project directory where build.gradle resides. The latest dependencies does get refreshed in the intelliJ. However it doesn’t referesh when using command line to open project using "idea . " aftering doing “./gradlew build”.Hence i see importability is still a open bug however one can circumvent the dependency importability process, by just using the IntelliJ UI to import the build.gradle. Not sure if i should assume & close this as resolved. Few cents welcomed.

BTW i did raise a bug …
Thank you,
Natty.


(Stefan Oehme) #10

This is not a bug, these scopes are intended. Please upgrade Idea to the latest version.


(Natty deor) #11

Stefan,

Thanks. Could you please elaborate which behaviour is not a bug?. You mean after running “.gradlew clean build” in command line with any gradle wrapper version in a project directory. the dependencies not appearing in list of external libraries within intellij. I am just trying to reason out the scopes that are intended. Could you please throw more light… thank you… BTW i use 2017.1.1 build of intellij


(Stefan Oehme) #12

This looks like a duplicate of https://github.com/gradle/gradle/issues/1276


(Chris Doré) #13

But what if you’re not using Idea’s Gradle importer? Seems like the idea plugin generates a broken project.


(Stefan Oehme) #14

What do you mean by broken? It works fine when calling gradle idea as well. All dependencies are in the right scope and I can access e.g. GSon at compile time and runtime.


(Chris Doré) #15

I’m not sure what happened, in one of my previous posts/tests I swear I got GSon only in the runtime scope. However, I just retested and everything is working.

Sorry for the red herring.


(Stefan Oehme) #16

No problem :slight_smile:


(Natty deor) #17

Stefan Oehme. I use the latest version of IntelliJ and the dependencies gets imported into the IDE only after i close the project and reimport the build.gradle to open a new project. It’s just weird that happens on my computer.I’ve also downgraded the wrapper version now. I am not entirely sure, what’s the underlying problem is thats stops or doesn’t enable me to work seamlessly to add dependencies and do ./gradlew build. I’ve referred ticket that you mentioned but i believe it’s not entirely related.


(Stefan Oehme) #18

You don’t call gradle build to add dependencies in the IDE. Instead click the refresh button in the Gradle tool window in IntelliJ. You can also activate “auto refresh” in IntelliJ’s Gradle settings.