'Docker image build failure

I have a spring boot application that works fine with intellij. However when I try to run the docker file it brakes due to this error [caused by implementation('io.sixhours:memcached-spring-boot-starter:2.4.2') this jar.]

The build runs perfectly fine from intellij. However memcached-spring-boot-starter jar does not get loaded from Docker file.

Here is the error log:--------->

2022-03-18 22:07:40.874  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [io.sixhours.memcached.cache.MemcachedCacheAutoConfiguration]; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2022-03-18 22:07:40.925 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [io.sixhours.memcached.cache.MemcachedCacheAutoConfiguration]; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
        at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:610)
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:311)
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250)
        at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:600)
        at org.springframework.context.annotation.ConfigurationClassParser.access$800(ConfigurationClassParser.java:111)
        at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:812)
        at java.util.ArrayList.forEach(ArrayList.java:1257)
        at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:809)
        at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:780)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:193)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
        at com.pitstop.catalogue.CatalogueApplication.main(CatalogueApplication.java:32)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
        at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
        at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
        at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
        at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
        at java.lang.Class.createAnnotationData(Class.java:3521)
        at java.lang.Class.annotationData(Class.java:3510)
        at java.lang.Class.getDeclaredAnnotations(Class.java:3477)
        at org.springframework.core.annotation.AnnotationsScanner.getDeclaredAnnotations(AnnotationsScanner.java:454)
        at org.springframework.core.annotation.AnnotationTypeMappings.addMetaAnnotationsToQueue(AnnotationTypeMappings.java:84)
        at org.springframework.core.annotation.AnnotationTypeMappings.addAllMappings(AnnotationTypeMappings.java:79)
        at org.springframework.core.annotation.AnnotationTypeMappings.<init>(AnnotationTypeMappings.java:68)
        at org.springframework.core.annotation.AnnotationTypeMappings.<init>(AnnotationTypeMappings.java:46)
        at org.springframework.core.annotation.AnnotationTypeMappings$Cache.createMappings(AnnotationTypeMappings.java:245)
        at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324)
        at org.springframework.core.annotation.AnnotationTypeMappings$Cache.get(AnnotationTypeMappings.java:241)
        at org.springframework.core.annotation.AnnotationTypeMappings.forAnnotationType(AnnotationTypeMappings.java:199)
        at org.springframework.core.annotation.AnnotationTypeMappings.forAnnotationType(AnnotationTypeMappings.java:182)
        at org.springframework.core.annotation.AnnotationTypeMappings.forAnnotationType(AnnotationTypeMappings.java:169)
        at org.springframework.core.annotation.TypeMappedAnnotation.of(TypeMappedAnnotation.java:597)
        at org.springframework.core.annotation.MergedAnnotation.of(MergedAnnotation.java:610)
        at org.springframework.core.type.classreading.MergedAnnotationReadingVisitor.visitEnd(MergedAnnotationReadingVisitor.java:95)
        at org.springframework.asm.ClassReader.readElementValues(ClassReader.java:3008)
        at org.springframework.asm.ClassReader.accept(ClassReader.java:608)
        at org.springframework.asm.ClassReader.accept(ClassReader.java:424)
        at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49)
        at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
        at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:86)
        at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:73)
        at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)
        at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:696)
        at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getMemberClasses(ConfigurationClassParser.java:993)
        at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:355)
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:272)
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250)
        at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:600)
        ... 28 common frames omitted

Here is my build.gradle file

buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
        id 'java'
        id 'org.springframework.boot' version '2.5.4'
        id 'io.spring.dependency-management' version '1.0.11.RELEASE'
        id "com.palantir.docker" version "0.26.0"
        id "com.palantir.docker-run" version "0.26.0"
        id 'pl.allegro.tech.build.axion-release' version '1.13.2'
        id 'com.appland.appmap' version '1.1.0'
}

scmVersion {
    repository {
        type = 'git'
        remote = 'origin'
    }
}

project.version = 'memcached-1'

group = 'com.pitstop.catalogue'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
    mavenCentral()
}

ext {
    runEnv = project.properties['runEnv'] ?: "stage"
    imageRegistry = project.properties['imageRegistry'] ?: "pitstop"
    bldJavaOpts = project.properties['bldJavaOpts'] ?: "-Xverify:none -XshowSettings:vm"
}

docker {
     name "${project.imageRegistry}/${project.name}/${bootJar.archiveBaseName.get()}:${project.version}-${project.runEnv}"
     files "./.dockerignore"
     files bootJar.destinationDirectory.get()
     files "./runapp.sh"
     buildArgs(['JAR_FILE': "${bootJar.archiveFileName.get()}", 'RUN_ENV': "${project.runEnv}", 'BLD_JAVA_OPTS': "${project.bldJavaOpts}", 'APP_VERSION': "${project.version}"])
}

tasks.getByPath('dockerPrepare').dependsOn('bootJar')
tasks.getByPath('docker').dependsOn('build')

dockerRun {
     name "${project.name}_${project.version}"
     image docker.name
     arguments '-P'
}

springBoot {
    buildInfo()
}

dependencies {
    implementation ('org.springframework.boot:spring-boot-starter-data-jpa') {
        exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
    }
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-cache'
    implementation 'io.micrometer:micrometer-registry-prometheus'

    implementation "org.hibernate.validator:hibernate-validator"
    implementation (group: 'com.zaxxer', name: 'HikariCP', version: '4.0.3') {
        exclude group: 'org.hibernate', module: 'hibernate-core'
    }

    implementation group: 'org.zalando', name: 'problem', version: '0.26.0'
    implementation group: 'org.zalando', name: 'problem-spring-web', version: '0.26.2'

    implementation "org.apache.commons:commons-lang3"
    implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
    implementation group: 'org.apache.poi', name: 'poi', version: '5.0.0'
    implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.0.0'
    implementation group: 'org.apache.commons', name: 'commons-compress', version: '1.21'

    implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
    implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '3.0.0'
    implementation group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.4.1'


    //aws sdk, these need to go together
    //from aws bom
    implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.163')
    implementation 'com.amazonaws:aws-java-sdk-s3'
    implementation 'com.amazonaws:aws-java-sdk-sqs'
    //extras
    implementation 'com.amazonaws:amazon-sqs-java-extended-client-lib:1.0.1'
    implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'

    runtimeOnly 'mysql:mysql-connector-java'
    implementation 'org.awaitility:awaitility:3.1.2'

    //eh cache as hibernate L2C
    implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.4.32.Final'
    implementation group: 'javax.cache', name: 'cache-api', version: '1.1.1'
    implementation group: 'org.hibernate', name: 'hibernate-jcache', version: '5.4.32.Final'
    implementation group: 'org.ehcache', name: 'ehcache', version: '3.10.0'
    //memcached
//  implementation group: 'com.google.code.simple-spring-memcached', name: 'simple-spring-memcached', version: '4.1.3'
//  implementation group: 'com.googlecode.xmemcached', name: 'xmemcached', version: '2.4.7'
    implementation('io.sixhours:memcached-spring-boot-starter:2.4.2')
    implementation group: 'com.google.guava', name: 'guava', version: '30.1.1-jre'
    implementation group: 'com.google.code.gson', name: 'gson'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

Here is the docker file:

FROM openjdk:8-jre-alpine3.9
ARG JAR_FILE
ARG RUN_ENV="dev"
ARG BLD_JAVA_OPTS="-Xverify:none -XshowSettings:vm"
ARG APP_VERSION="unknown"
LABEL "com.getpitstop.app"="catalogue" "com.getpitstop.env"=${RUN_ENV} "com.getpitstop.ver"=${APP_VERSION}
ENV SPRING_PROFILES_ACTIVE=${RUN_ENV} JAVA_OPTS=${BLD_JAVA_OPTS}
RUN addgroup -S pitstop && adduser -S pitstop -G pitstop
WORKDIR /app
RUN chown pitstop:pitstop .
COPY --chown=pitstop:pitstop . .
RUN mkdir -p /data/tmp && chown -R pitstop:pitstop /data
RUN mv ${JAR_FILE} pitstop-catalogue.jar
EXPOSE 8080/tcp
USER pitstop:pitstop
ENTRYPOINT ["./runapp.sh", "pitstop-catalogue.jar"]
CMD ["--server.port=8080"]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source