spring gradle don't build boot jar
- Ensure the 'plugins' block in your build.gradle file includes the 'org.springframework.boot' and 'io.spring.dependency-management' plugins:
plugins {
id 'org.springframework.boot' version '2.5.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
// other plugins...
}
- Apply the 'java' plugin to enable Java compilation:
apply plugin: 'java'
- Define the Spring Boot dependencies in the 'dependencies' block:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
// other dependencies...
}
- Make sure the 'main' class is specified in the 'springBoot' block:
springBoot {
mainClassName = 'com.example.YourApplicationClass'
}
Replace 'com.example.YourApplicationClass' with the actual package and class name of your main application class.
- Ensure that the 'sourceCompatibility' and 'targetCompatibility' are set to the Java version you are using:
sourceCompatibility = '11'
targetCompatibility = '11'
Replace '11' with your Java version.
- Verify that the 'repositories' block includes the necessary repositories:
repositories {
mavenCentral()
// other repositories...
}
- Run the 'bootJar' task to build the Spring Boot JAR:
./gradlew bootJar
Replace './gradlew' with 'gradlew.bat' if you are using Windows.
- Locate the generated JAR file in the 'build/libs' directory:
ls build/libs/
Replace 'ls' with 'dir' if you are using Windows. The JAR file should have a name like 'your-application-name-1.0.0-SNAPSHOT.jar', where 'your-application-name' is the name of your application.
- Verify that the JAR file can be executed:
java -jar build/libs/your-application-name-1.0.0-SNAPSHOT.jar
Replace 'your-application-name-1.0.0-SNAPSHOT.jar' with the actual name of your JAR file.
- If any issues arise, review the build output and resolve any reported errors or missing dependencies.