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.
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.
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?
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.
./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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.