Gradle integration : external dependencies not in classpath on run / debug

Answered

Hi,

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.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

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.

This is not systematic BTW, it sometimes works fine (and my dependencies are in the classpath) but eventually stops working.

What am I doing wrong ? Thanks !

There is nothing too exotic about my debug / run configuration, it's pretty much default : 

1
4 comments
Avatar
Permanently deleted user

Thank you ! Don't know how I missed this one... I'm actually on gradle 3.5 but maybe the bug wasn't fixed. Will update my IntelliJ and report back if it still doesn't work. 

0

It affects all Gradle versions 3.4+ because of the changes in Gradle.

1
Avatar
Permanently deleted user

Thanks a lot Serge, Updating to 2017.1 solved this.

0

Please sign in to leave a comment.