Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

indirect jar conflict between spring-security-rest and guava causing NoSuchMethod error

I use grails 3.1.16

build.gradle:

dependencies {
    compile "com.google.guava:guava:18.0"
    compile "org.grails.plugins:spring-security-rest:2.0.0.M2"
}

while running this code:

   private LoadingCache<String, Boolean> attempts

    @PostConstruct
    void init() {
        Integer time = ApplicationContextHolder.getProperty(ApplicationContextHolder.config.time)
        attempts = CacheBuilder.newBuilder()
                .expireAfterWrite(time, TimeUnit.MINUTES)
                .build({ 0 } as CacheLoader)
    }

I am getting the following errors:

Caused by: java.lang.NoSuchMethodError: com.google.common.base.Platform.systemNanoTime()J
        at com.google.common.base.LocalCache(Ticker.java:60)
        at com.google.common.cache.LocalCache$Segment.put(LocalCache.java:2827)
        at com.google.common.cache.LocalCache.put(LocalCache.java:4149)
        at com.google.common.cache.LocalCache$LocalManualCache.put(LocalCache.java:4754)
        at com.google.common.cache.Cache$put.call(Unknown Source)

After running dependency-report, I found out that the issue was caused by a dependency of the Spring Security REST Plugin: ( com.google.guava:guava-base:r03) - with the same package name "com.google.common.base" and Platform.class with no such method systemNanoTime()

|    +--- org.grails.plugins:spring-security-rest:2.0.0.M2
|    |    +--- com.google.guava:guava-io:r03
|    |    |    +--- com.google.guava:guava-annotations:r03
|    |    |    \--- com.google.guava:guava-base:r03
|    |    |         \--- com.google.guava:guava-annotations:r03

Any ideas to solve this ?

like image 541
Tom Boldan Avatar asked Jan 02 '18 14:01

Tom Boldan


2 Answers

Step 1. Please check with updated dependencies(issue may be reported):

dependencies {
    compile 'org.grails.plugins:spring-security-rest:2.0.0.RC1'
    compile 'com.google.guava:guava:24.0-jre'
}

You can check spring-security-rest documentation and repo and for guava documentation and repo

OR

Step 2.

compile("org.grails.plugins:spring-security-rest:2.0.0.RC1") {
            excludes([group: 'com.google.guava:guava'])
}

OR

Step 3. in your build.gradle you can exclude the compiled classes from the JAR file:

jar {
 exclude "com/google/guava/**/**"
}

or you can refer grails documentation

like image 107
Rahul Mahadik Avatar answered Oct 28 '22 02:10

Rahul Mahadik


Have you tried?

dependencies {
    compile "com.google.guava:guava:18.0"
    compile ("org.grails.plugins:spring-security-rest:2.0.0.M2") {
        exclude module: 'guava-base'

        // can also be specified with group
        // exclude group: 'com.google.guava', module: 'guava-base'
    }
}

This will exclude the transitive dependency of guava-base from spring-security-rest.

like image 26
dmahapatro Avatar answered Oct 28 '22 02:10

dmahapatro