Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MACOSX - java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V

so this one's a doozy and I'd love some help.

Here's the error that I am getting

getS3Client(): Exception: java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V

when I try to run this block of code

GrailsApplication grailsApplication

// Amazon AWS S3 properties
private awsProps = [  "loaded"      : false
                      , "S3Bucket"    : ""
                      , "AccessKeyId" : ""
                      , "AccessKeyPsw": ""
]

def getS3Client ( ) {
  try {
    if ( ! awsProps.loaded ) {
       loadAwsProperties()
    }

    def awsCreds = new BasicAWSCredentials( awsProps.AccessKeyId, awsProps.AccessKeyPsw )

    AmazonS3 s3Client
    s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials( new AWSStaticCredentialsProvider( awsCreds ) )
                .withRegion( Regions.US_EAST_1 )
                .build()

        return s3Client
   } catch ( Throwable t ) {
        log.error ( "getS3Client(): Exception: ${t}" )
        return null
    }
}

Here's my dependencies at the top of the file

import com.amazonaws.HttpMethod
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials

import com.amazonaws.regions.Regions

import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.*
import com.burris.portal.utils.Utils
import grails.core.GrailsApplication

import javax.imageio.ImageIO
import javax.imageio.ImageReader
import javax.imageio.stream.ImageInputStream
import java.awt.Graphics2D
import java.awt.RenderingHints
import java.awt.image.BufferedImage

import grails.gorm.transactions.Transactional
import groovy.util.logging.Log4j

Here's my build.gradle file dependencies

* FOR AMAZON S3 force these org.apache.httpcomponents to the top of the classpath
 */
configurations.all {
    resolutionStrategy.force 'org.apache.httpcomponents:httpcore:4.4.9', 'org.apache.httpcomponents:httpclient:4.5.5'
}

/* Continue with other necessary dependencies */
dependencies {

    /* FOR AMAZON S3 */
    compile 'org.apache.httpcomponents:httpcore:4.4.9'
    compile "org.apache.httpcomponents:httpclient:4.5.5"
    compile "com.amazonaws:aws-java-sdk-s3:1.11.328"

    /* FOR GROOVY HTTP */
    compile "org.codehaus.groovy.modules.http-builder:http-builder:0.6"
    ...
 }

Now here's the kicker, it works in almost all other developer machine except my own and I have not been able to figure out why.

This is a groovy on grails project and the build engine I am using is gradle with java.

Here are my versions, though I have tested out several others that work on my colleague's machines but not mine for some reason

java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

gradle --version

------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------

Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_181 (Oracle Corporation 25.181-b13)
OS:           Mac OS X 10.13.6 x86_64

grails --version
| Grails Version: 3.2.11
| Groovy Version: 2.4.11
| JVM Version: 1.8.0_181

gradle dependencies --configuration=testRuntime | grep httpcore
    +--- org.apache.httpcomponents:httpcore:4.4.9
    |    +--- org.apache.httpcomponents:httpcore:4.4.9
    |         |    |    +--- org.apache.httpcomponents:httpcore:4.3 -> 4.4.9
    |         |    |    \--- org.apache.httpcomponents:httpcore-nio:4.3
    |         |    |         \--- org.apache.httpcomponents:httpcore:4.3 -> 4.4.9

Here's what I have tried

  1. Upgraded and downgraded my java version, gradle, grails, and groovy version with no success. My co-workers have it working on gradle 3.1 and 4.8, so I don't think the issue lies here.
  2. Switched from openJDK to OracleJDK with no luck.
  3. Blew away my gradle dependencies on the global home directory and local repo directory via rm -rf ~/.gradle and rm -rf ./gradle and rm build/.dependencies to force download all repo over again with no success
  4. Tried /gradlew clean build with no success
  5. Cloned the repo to a different repo and the same result happened
  6. Restarted the computer and that didn't work either
  7. Looked over GitHub and StackOverflow and that led me to think that upgrading my version of httpcore would help, except all of my gradle dependencies for httpcore are exactly the same as another computer that runs the method fine (see above)

Here's my MAC OSX version - macOS High Sierra Version 10.13.6

So any and all help would be appreciated as I am at the end of my wits here. The application runs fine on almost all other situations but just breaks right at that method.

like image 519
superjisan Avatar asked Aug 28 '18 20:08

superjisan


Video Answer


1 Answers

I had the same issue. In my case this thread bellow helped me to fixe my issue. enter link description here

I have httpclient:4.5.9 and httpclient:4.3. Then I updated httpcore to a version higher then 4.4.

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpasyncclient</artifactId>
        <version>4.5.9</version>
      <exclusions>
        <exclusion>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpcore</artifactId>
      <version>4.4.11</version>
    </dependency>
like image 183
onlyme Avatar answered Oct 05 '22 02:10

onlyme