Organize the steps to create a Spring Boot project in IntelliJ IDEA. This time, Java and Gradle will be used.
Launch IntelliJ and click ** Create New Project **.
Select Gradle, Java and click ** Next **.
Create a project as SprintBootTest.
Build.gradle created in the project
build.gradle
plugins {
id 'java'
}
group 'com.ykdevs'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Edit as follows. The latest version is specified from Spring Boot. Since IntelliJ is used, idea is specified for plugins. Reference JUnit uses JUnit5.
build.gradle
buildscript {
ext {
springBootVersion = '2.3.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'idea' // IntelliJ
id 'java'
}
group 'com.ykdevs'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
// SpringBoot
implementation "org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
// JUnit
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}
The following directories are created when the project is created.
src
├─ main
│ │
│ ├─ java
│ │
│ └─ resources
└─ test
│
├─ java
│
└─ resources
Create a package under main / java.
If you specify the package names separated by commas, the directory will be created automatically.
Create an application class file in the package directory.
Annotate @SpringBootApplication and create main function.
Application.java
package com.ykdevs.springboottest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Right-click on the class name and select Generate to create a Test.
The test looks like the following.
package com.ykdevs.springboottest;
import org.junit.jupiter.api.Test;
class ApplicationTest {
@Test
void main() {
Application.main(new String[0]);
}
}
Gradle User Guide Introduction to Spring Boot-Official Documents JUnit 5 User Guide
Recommended Posts