Gradle external dependencies not in classpath

(Hugo Migneron) #1

Hi, I regularly run into a fairly peculiar problem.

My build.gradle file includes a number of external dependencies :

def grpcVersion = '1.0.3'
dependencies {
    compile "io.grpc:grpc-netty:${grpcVersion}"
    compile "io.grpc:grpc-protobuf:${grpcVersion}"
    compile "io.grpc:grpc-stub:${grpcVersion}"
    // ...

I’m using IntelliJ IDEA 2016.3.1 with the Gradle integration.

From the Gradle window, when I click Refresh All Gradle Projects, I see the external dependencies just fine. All the jars are in my .gradle/caches folder, etc. Looking at my project structure, all the dependencies are “Provided” :

However, running / debugging directly from IntelliJ, I get a ClassNotFoundException on one of my dependencies :

Caused by: java.lang.ClassNotFoundException: io.grpc.BindableService
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(

Digging a bit deeper, I realized that my dependencies were missing from the -classpath argument altogether!

Going back to the Project Structure window and marking the dependencies as “Compile” one by one and then running again was the only way to get them to be included in the -classpath argument (thus getting rid of the ClassNotFoundException).

This would be fine if it stayed that way, but every single time I “Refresh All Gradle Projects” (because I add a dependency or whatever) they go back to “Provided” and I run into the error once again.

I’ve tried to : restart IntelliJ / restart my machine / gradle clean / gradle build / swear at it but nothing works. I have no idea how to get out of that state once I get into.

What’s driving me nuts is that this isn’t systematic. If I delete the entire repo and git clone again things will work just fine for a while until I run into the problem again at a seemingly random time.

What am I doing wrong ? Thanks !

Extra info : Running gradle --version yields :

Gradle 3.5

Build time:   2017-04-10 13:37:25 UTC
Revision:     b762622a185d59ce0cfc9cbc6ab5dd22469e18a6

Groovy:       2.4.10
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_112 (Oracle Corporation 25.112-b16)
OS:           Mac OS X 10.12.5 x86_64

(Hugo Migneron) #2

This turned out to be caused by the version of IntelliJ I was running. Updating to 2017.1 solved this (apparently a compatibility problem between gradle 3.4 + and IntelliJ 2016.x).