Home > Enterprise >  Spring Boot - Gradle - No auto configuration classes found in META-INF/spring.factories
Spring Boot - Gradle - No auto configuration classes found in META-INF/spring.factories

Time:05-13

when I start app in idea it works well but when i try to start this app from cmd like java -jar build/libs/dev-0.0.1-SNAPSHOT.jar

i get this error

21:02:06.634 [main] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.

this is my build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 */

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:2.6.7"
    }
}

plugins {
    id 'java'
    id 'groovy'
    id 'maven-publish'
}

repositories {
    mavenLocal()
    maven {
        url = uri('https://repo.maven.apache.org/maven2/')
    }
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-security:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-validation:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-web:2.6.7'
    implementation 'org.springframework.boot:spring-boot-configuration-processor:2.6.7'
    implementation 'org.springframework:spring-aop:5.3.19'

    compileOnly 'org.projectlombok:lombok:1.18.24'
    annotationProcessor 'org.projectlombok:lombok:1.18.24'
    testCompileOnly 'org.projectlombok:lombok:1.18.24'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'

    implementation 'org.mapstruct:mapstruct:1.4.2.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'

    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'io.jsonwebtoken:jjwt:0.9.1'
    implementation 'com.vladmihalcea:hibernate-types-52:2.16.2'
    implementation 'org.flywaydb:flyway-core:8.5.10'

    runtimeOnly 'org.postgresql:postgresql:42.3.4'

    testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.7'
    testImplementation 'org.springframework.security:spring-security-test:5.6.3'
    testImplementation 'org.codehaus.groovy:groovy-all:3.0.10'
    testImplementation 'org.spockframework:spock-core:2.1-groovy-3.0'
    testImplementation 'org.spockframework:spock-spring:2.1-groovy-3.0'
    testImplementation 'org.testcontainers:spock:1.17.1'
    testImplementation "org.testcontainers:postgresql:1.17.1"
}

group = 'com.dev'
version = '0.0.1-SNAPSHOT'

sourceCompatibility = '17'
targetCompatibility = '17'

java.sourceCompatibility = JavaVersion.VERSION_17

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

test {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}

compileJava {
    options.compilerArgs  = "-Amapstruct.defaultComponentModel=spring"
    options.compilerArgs  = "-Amapstruct.unmappedTargetPolicy=WARN"
}

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
        attributes(
                'Main-Class': 'com.dev.DevApplication',
                'Class-Path': configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(' ')
        )
    }
    from{
        configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it)}
    }
}

CodePudding user response:

So i edited build.gradle like this and it is working now

/*
 * This file was generated by the Gradle 'init' task.
 */

plugins {
    id 'java'
    id 'groovy'
    id 'maven-publish'
    id 'org.springframework.boot' version '2.6.7'
}

repositories {
    mavenLocal()
    maven {
        url = uri('https://repo.maven.apache.org/maven2/')
    }
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-security:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-validation:2.6.7'
    implementation 'org.springframework.boot:spring-boot-starter-web:2.6.7'
    implementation 'org.springframework.boot:spring-boot-configuration-processor:2.6.7'
    implementation 'org.springframework:spring-aop:5.3.19'

    compileOnly 'org.projectlombok:lombok:1.18.24'
    annotationProcessor 'org.projectlombok:lombok:1.18.24'
    testCompileOnly 'org.projectlombok:lombok:1.18.24'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'

    implementation 'org.mapstruct:mapstruct:1.4.2.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'

    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'io.jsonwebtoken:jjwt:0.9.1'
    implementation 'com.vladmihalcea:hibernate-types-52:2.16.2'
    implementation 'org.flywaydb:flyway-core:8.5.10'

    runtimeOnly 'org.postgresql:postgresql:42.3.4'

    testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.7'
    testImplementation 'org.springframework.security:spring-security-test:5.6.3'
    testImplementation 'org.codehaus.groovy:groovy-all:3.0.10'
    testImplementation 'org.spockframework:spock-core:2.1-groovy-3.0'
    testImplementation 'org.spockframework:spock-spring:2.1-groovy-3.0'
    testImplementation 'org.testcontainers:spock:1.17.1'
    testImplementation "org.testcontainers:postgresql:1.17.1"
}

group = 'com.dev'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
targetCompatibility = '17'

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

test {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}

compileJava {
    options.compilerArgs  = "-Amapstruct.defaultComponentModel=spring"
    options.compilerArgs  = "-Amapstruct.unmappedTargetPolicy=WARN"
}

jar {
    enabled = false
}

springBoot {
    mainClass = 'com.dev.DevApplication'
}
  • Related