java.lang.NoSuchMethodException: org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.<init>() in GRADLE project

Viewed 1882

I am having a Gradle spring-boot project and getting the following error when starting the application.

Ran this cmd: gradle clean bootRun --warning-mode all

ptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
14:06:27.154 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: Unable to instantiate factory class: org.springframework.boot.env.EnvironmentPostProcessor
        at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:167)
        at org.springframework.core.io.support.SpringFactoriesLoader.loadFactories(SpringFactoriesLoader.java:104)
        at org.springframework.boot.context.config.ConfigFileApplicationListener.loadPostProcessors(ConfigFileApplicationListener.java:183)
        at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:173)
        at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:163)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
        at app.EventsApplication.main(EventsApplication.java:25)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NoSuchMethodException: org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.<init>()
        at java.base/java.lang.Class.getConstructor0(Class.java:3349)
        at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)
        at org.springframework.util.ReflectionUtils.accessibleConstructor(ReflectionUtils.java:530)
        at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:164)
        ... 20 common frames omitted
    
BUILD SUCCESSFUL in 7s

I tried updating to the newer version of gradle to springboot and even deleted the local cache. Restarted the intellij by invalidating the cache etc,but no luck.

This is the build.gradle file.

buildscript {
  dependencies {
    classpath 'org.postgresql:postgresql:42.2.24'
    classpath 'com.smartnews:jpa-entity-generator:0.99.8'
      classpath("org.springframework.boot:spring-boot-gradle-plugin:2.4.0.RELEASE")
  }
}

plugins {
//    id 'com.diffplug.spotless' version '5.15.1'
    id 'com.github.ben-manes.versions' version '0.39.0'
    id 'com.github.johnrengelman.processes' version '0.5.0'
    id 'com.github.spotbugs' version '4.7.5'
    id 'com.star-zero.gradle.githook' version '1.2.1'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'org.flywaydb.flyway' version '7.15.0'
    id 'org.springframework.boot' version '2.4.0'
    id 'org.owasp.dependencycheck' version '6.3.2'
    id 'org.sonarqube' version '3.3'
    id 'org.springdoc.openapi-gradle-plugin' version '1.3.3'
    id 'pl.allegro.tech.build.axion-release' version '1.13.3'
    id 'ru.netris.commitlint' version '1.4.1'
    id 'se.bjurr.gitchangelog.git-changelog-gradle-plugin' version '1.71.4'
    id 'checkstyle'
    id 'java'
    id 'jacoco'
    id 'pmd'
}

group = 'app'
version = "1.0.0"
//sourceCompatibility = '11' VERSION_11
java.sourceCompatibility = JavaVersion.VERSION_11
apply plugin: 'entitygen'

repositories {
    mavenCentral()
//    mavenLocal()
    maven {
        url "http://nexus.infra.cloud.247-inc.net:8080/nexus/repository/greleases/"
        allowInsecureProtocol = true
    }
}

sourceSets {
    integrationTest {
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
    smokeTest {
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
}

processResources {
    filesMatching("**/application.properties") {
        expand(project.properties)
    }
}

dependencies {
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
    annotationProcessor 'org.projectlombok:lombok:1.18.22'
    annotationProcessor 'org.projectlombok:lombok-mapstruct-binding:0.2.0'
    implementation 'assist:kafka-connector:4.0.0'
    implementation 'org.projectlombok:lombok:1.18.22'
    implementation 'org.mapstruct:mapstruct:1.4.2.Final'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'io.jsonwebtoken:jjwt:0.9.1'
    implementation 'io.springfox:springfox-boot-starter:3.0.0'
    implementation 'io.springfox:springfox-swagger-ui:3.0.0'
    runtimeOnly 'org.postgresql:postgresql:42.2.24'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.assertj:assertj-core:3.21.0'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
    testImplementation 'org.testcontainers:testcontainers:1.16.0'
    testImplementation 'org.testcontainers:junit-jupiter:1.16.0'
    testImplementation 'org.testcontainers:postgresql:1.16.0'
    developmentOnly("org.springframework.boot:spring-boot-devtools")

    integrationTestImplementation sourceSets.main.runtimeClasspath
    integrationTestImplementation sourceSets.test.runtimeClasspath
    smokeTestImplementation sourceSets.main.runtimeClasspath
    smokeTestImplementation sourceSets.test.runtimeClasspath
}

githook {
    failOnMissingHooksDir = false
    hooks {
        'commit-msg' {
            task = 'commitlint'
        }
    }
}

openApi {
    outputDir = file('build/docs')
}

bootBuildImage {
    imageName = 'spring-api:latest'
}

checkstyle {
    toolVersion = '9.0'
    configFile = file('checkstyle.xml')
}

pmd {
    toolVersion = '6.38.0'
    ignoreFailures = true
}

//spotless {
//    java {
//        target 'src/**/*.java'
//        importOrder()
//        removeUnusedImports()
//        prettier([
//            'prettier': '2.4.1',
//            'prettier-plugin-java': '1.4.0'
//        ]).configFile('.prettierrc')
//    }
//}

spotbugs {
  toolVersion = '4.4.1'
    ignoreFailures = true
}

sonarqube {
    properties {
        property 'sonar.projectKey', 'voice-reporting-events-generator'
        property 'sonar.projectName', 'voice-reporting-events-generator'
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.jacoco.reportPath", "./build/jacoco/test.exec"
        property "sonar.host.url", "http://sonar.cicd.247-inc.net:8080"
        property "sonar.sources", "./src/main/java"
        property "sonar.tests", "./src/test/java"
        property "sonar.java.binaries", "./build/classes/java/main/"
        property "sonar.java.test.binaries", "./build/classes/java/test/"
        property "sonar.inclusions", "**/*.java"
        property "sonar.exclusions", "**/*Generated.java"
        property "http.proxyHost", "10.64.99.240"
        property "http.proxyPort", "3128"
        property "https.proxyHost", "10.64.99.240"
        property "https.proxyPort", "3128"
    }
}

flyway {
    url = DB_URL
    user = DB_USER
    password = DB_PASSWORD
}

entityGen {
    configPath = 'src/main/resources/db/entity-generator.yaml'
}

jacoco {
    toolVersion = '0.8.7'
}

jacocoTestReport {
    dependsOn test
    finalizedBy jacocoTestCoverageVerification
    reports {
        xml.required = true
    }
}

jacocoTestCoverageVerification {
    dependsOn test
    violationRules {
        rule {
            limit {
                minimum = 0.5
            }
        }
    }
}

test {
    finalizedBy jacocoTestReport
    useJUnitPlatform()
    testLogging {
        exceptionFormat = 'full'
    }
}

task integrationTest(type: Test) {
    description = 'Runs the integration tests.'
    group = 'Verification'
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath

    useJUnitPlatform()
    testLogging {
        exceptionFormat = 'full'
    }
}

task smokeTest(type: Test) {
    description = 'Runs the smoke tests.'
    group = 'Verification'
    testClassesDirs = sourceSets.smokeTest.output.classesDirs
    classpath = sourceSets.smokeTest.runtimeClasspath

    useJUnitPlatform()
    testLogging {
        exceptionFormat = 'full'
    }
}

task generateEntities(type: Exec) {
    description = 'Generates the entities sources.'
    group = 'Build'
    commandLine './gradlew', 'entityGen', 'format'
    environment([DB_URL: DB_URL, DB_USER: DB_USER, DB_PASSWORD: DB_PASSWORD])
    doLast {
        ant.replace(token: '\\\"', value: '') {
            fileset(dir: 'src/main/java/app/entity')
        }
    }
}

task lint() {
    dependsOn 'formatCheck', 'checkstyle' , 'pmd', 'spotbugs'
    description = 'Runs several static code analysis.'
    group = 'Verification'
}

task checkstyle() {
    dependsOn 'checkstyleIntegrationTest', 'checkstyleMain', 'checkstyleSmokeTest', 'checkstyleTest'
    description = 'Runs Checkstyle analysis for the source folder.'
    group = 'Verification'
}

task pmd() {
    dependsOn 'pmdIntegrationTest', 'pmdMain'
    description = 'Runs PMD analysis for the source folder.'
    group = 'Verification'
}

task spotbugs() {
    dependsOn 'spotbugsIntegrationTest', 'spotbugsMain', 'spotbugsSmokeTest', 'spotbugsTest'
    description = 'Runs SpotBugs analysis for the source folder.'
    group = 'Verification'

    tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
        reports {
            html.enabled = true
        }
    }
}

task format() {
    dependsOn 'spotlessApply'
    description = 'Applies code formatting steps to source code in-place.'
    group = 'Verification'
}

task formatCheck() {
    dependsOn 'spotlessCheck'
    description = 'Checks that source code satisfies formatting steps.'
    group = 'Verification'
}

task generateChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
    description = 'Generates a changelog from GIT repository.'
    group = 'Release'
    fromRepo = file('.')
    file = file('CHANGELOG.md');
    templateContent = file('changelog.mustache').getText('UTF-8');
}

task deploy(type: Exec) {
    commandLine 'ansible-playbook', 'cicd/deploy/deploy-to-swarm.yaml'
    description = 'Deploys the application to Docker Swarm.'
    group = 'Release'
}

jar {
    baseName = 'base-name'
    version = '1.0.0'
    manifest {
        attributes 'Main-Class': 'app.EventsApplication'
    }
}
task fatJar(type: Jar) {
    manifest.from jar.manifest
//    classifier = 'all'
    from {
        configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
    } {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
    }
    with jar
}

artifacts {
    archives fatJar
}

springBoot {
    buildInfo()
}

bootJar {
    archiveBaseName = rootProject.name
    archiveVersion =  rootProject.version
}

ext {
    set('springCloudVersion', "Hoxton.SR8")
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

0 Answers
Related