Gradle build successful but jar is showing NoClassDefFoundError

Viewed 412

I am new to gradle, when i run my application the build is successful and jar file is created but when I run the jar file, it gives me this NoClassDefFoundError error enter image description here

I am trying to convert a maven project to Gradle, i first used gradle init to convert it into this,The pipeline succeeds on jenkins but on rancher it shows the same error in pod so i thought it might be a Docker issue so downloaded and ran the repo On Intelllij Locally. please help! I have been stuck on this issue for sometime. This is my build.gradle file


buildscript {
    ext {
        springBootVersion = '2.5.5'
    }
    repositories {
        maven {
            url = 'xyz/artifactory/edai-maven-virtual'
        }
        maven {
            url = 'xyz/artifactory/edai-maven-virtual'
        }
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.17"
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

//apply plugin: 'org.apache.maven.plugins'
//apply plugin: 'com.google.code.maven-replacer-plugin'

//mainClassName = 'DdBuildConfigServiceApplication'

repositories {
    maven {
        maven {
            url = 'xyz/artifactory/edai-maven-virtual'
        }
    }
    mavenCentral()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}

version= '0.0.1'

def grpcVersion = '1.39.0'
dependencies {
    implementation group: 'io.grpc', name: 'grpc-netty-shaded', version: "${grpcVersion}" // For SSL security
    implementation group: 'io.grpc', name: 'grpc-protobuf', version: "${grpcVersion}"
    implementation group: 'io.grpc', name: 'grpc-stub', version: "${grpcVersion}"
    implementation group: 'com.google.api.grpc', name: 'googleapis-common-protos', version: "0.0.3"
    implementation 'javax.annotation:javax.annotation-api:1.3.2'

    //SpringBoot dependency
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.5.5'
    //implementation group: 'org.springframework.boot', name: 'spring-core', version: '5.3.7'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.5.5'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.5.5'
    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.5.5'

    

}


jar {
  manifest {
    attributes('Main-Class':'com.xyz.ddconfig.DdBuildConfigServiceApplication')
       
  } 
}
sourceSets {
    main {
        java {
            srcDirs = ['/src/main/java']
        }
        resources {
            srcDirs = ['/src/main/resources']
        }
    }
}

tasks.jar {
    enabled = true
    // Remove `plain` postfix from jar file name
    archiveClassifier.set("")
}

tasks.named('test') {
    useJUnitPlatform()
}

application {
    // Define the main class for the application.
  mainClass = 'com.xyz.ddconfig.DdBuildConfigServiceApplication'
}

1 Answers

I see you are using spring-boot; you need to run bootJar or bootWar based on your needs which creates a uber (fat) jar

Related