I've created a fat-jar file from my spring boot project by using shadow gradle plugin.
Below is part of my build.gradle file:
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
}
jar {
manifest {
attributes(
'Main-Class': 'com.security.login.LoginApplication',
'Class-Path': '/libs/authentication.jar'
)
}
}
After implementing shadow plugin I created a jar file with shadowJar task. But when running the jar file with this command:
java -jar authentication-0.0.1-SNAPSHOT-all.jar
I encounter with this error:
....
17:26:49.343 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed
....
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:186)
at org.springframework.boot.autoconfigure.jdbc.PropertiesJdbcConnectionDetails.getDriverClassName(PropertiesJdbcConnectionDetails.java:49)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:55)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:117)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140)
This application runs correctly in IntelliJ but the fat-jar file has error.
any help is appreciated.
Update
I also tried this method to create a fat-jar:
task customFatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'com.security.login.LoginApplication'
}
archiveBaseName = 'PackageDemoJAR'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
But the error still exists!