New Gradle version creates conflict with depedency

(Guy Grinwald) #1

I have a simple build script (shorted for clarity) which uses Guava as a dependency

group 'test'
version '0.1.0'

apply plugin: 'java'
apply plugin: 'application'

sourceCompatibility = 1.8
targetCompatibility = 1.8

mainClassName = 'Test'

repositories {mavenCentral()}
task wrapper(type: Wrapper) {gradleVersion = '3.5'}
dependencies {compile ''}

When running this code:

public class Test {
    public static void main(String[] args) {
        LoadingCache<Long, String> applicantCache = CacheBuilder.newBuilder()
                .expireAfterAccess(31, TimeUnit.DAYS)
                .build(new CacheLoader<Long, String>() {
                    public String load(Long key) {
                        return "";

I get this error:

java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(
	at java.lang.Class.privateGetMethodRecursive(
	at java.lang.Class.getMethod0(
	at java.lang.Class.getMethod(
	at sun.launcher.LauncherHelper.validateMainClass(
	at sun.launcher.LauncherHelper.checkAndLoadMain(
Caused by: java.lang.ClassNotFoundException:
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" 

When downgrading the Gradle Wrapper version to 3.3 the problem is fixed but, I need version 3.5 for something else that is not feasible in version 3.3. As far as I can understand there is some dependency conflict between this version of Gradle and Guava but according to this post - it is not possible.

I know the jar is in place + using gradle dependencyInsight --dependency shows that the dependency exists:

\--- compile

Thanks for any help

(Guy Grinwald) #2

Hi, if anyone else encounters similar issues the answer is here.

A bug in my Intellij version caused compile scoped dependencies to transform into provided dependencies by Intellij. Upgrading the Intellij version solved the issue.