Open mingning179 opened 6 months ago
To initialize a Spring Boot project with Gradle and YAML configuration, we need to set up the Gradle wrapper with the latest version, create a basic Spring Boot application class, configure the application.yaml
file, and prepare the build script with the necessary dependencies and plugins.
Update gradle-wrapper.properties
:
Create application.yaml
:
src/main/resources/application.yaml
with the basic Spring Boot configuration.Create DemoApplication.java
:
src/main/java/com/example/demo/DemoApplication.java
with the @SpringBootApplication
annotation and the main method to run the Spring Boot application.Update build.gradle
:
processResources
block.Generate or create gradlew
and gradlew.bat
:
gradle wrapper
command.gradlew
and gradlew.bat
files with the standard wrapper scripts.Here are the detailed steps and code snippets:
gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
Replace 7.5
with the latest version if there is a newer one.
application.yaml:
spring:
application:
name: demo-application
server:
port: 8080
DemoApplication.java:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
build.gradle:
plugins {
id 'org.springframework.boot' version '2.7.4' // Replace with the latest version
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
processResources {
filesMatching('**/*.properties') {
filter {
it.replace('.properties', '.yaml')
}
}
}
gradlew and gradlew.bat:
gradle wrapper
in the project directory to generate the wrapper files.gradlew
as executable with chmod +x gradlew
.After implementing these changes, you should have a basic Spring Boot project using Gradle and YAML configuration ready to be built and run.
Click here to create a Pull Request with the proposed solution
Files used for this task:
@codeautopilot Init springboot springboot use the last version use yaml and gradle