Until building Spring-Boot using Eclipse on Mac (Gradle version)

Introduction

Environment construction and Hello World take 90% of the development time, so I created an article to solve it.

environment

MacOS Mojave 10.14.3
Eclipse 4.11.0
Gradle 5.5

Creating a rough environment

I will omit the JDK and Eclipse because I think they will come out if I google.
If you set the JDK version to 10 or 9, it may not work, so I think you should set it to about 8.
Install the latest version of Eclipse. I dropped Japanese.

Project creation

The template is easy, so use Spring Initializr.
Of course you can do it from Eclipse, but
At first you will be worried about dependencies, so it is better to do it with GUI first from articles that are likely to be used to some extent on the net. I do not think. image.png
For the time being, select Gradle, the language is Java, and the Spring Boot version can be left as it is.
Group is the root package name. You don't have to think so deeply. This time it was com.p0ngch4ng.labo.
Artifact is the project name. Give it a name for what you want to make.
image.png
Dependencies are dependencies. Since you can add it later, add only JPA, MySQL, and Web at first.

image.png
If you open the dropped zip, it will look like this.
Import this into Eclipse if there is nothing missing.
image.png
Select an existing Grale project and unzip the downloaded zip file Select as the project root directory. After that, hit the next one repeatedly.

Then, I think that the project can be developed like this.
image.png


At this point, the project is ready for the time being.
All you have to do is start from here.

Setup for the time being

~~ I probably chose MySQL as a dependency, but I didn't specify the database in Build.Gradle [^ 1] ~~ You can set it up as it is, but if you have never touched SQL or want to execute it for the time being, I would like to execute it without annoying settings.

Therefore,

implementation 'org.hsqldb:hsqldb:2.3.2'

Let's add this one sentence to Gradle.build

plugins {
	id 'org.springframework.boot' version '2.1.6.RELEASE'
	id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com.p0ngch4ng'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
tasks.withType(AbstractCompile)*.options*.encoding = 'UTF-8'
configurations {
	developmentOnly
	runtimeClasspath {
		extendsFrom developmentOnly
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	runtimeOnly 'mysql:mysql-connector-java'
    //Add here!
    //
	implementation 'org.hsqldb:hsqldb:2.3.2'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'

}

If you add it, it will not be updated as it is, so right-click on the project and select Gradle → Refresh Dependencies. [^ 2]

By doing this, it will refer to the database without any special settings, so if you do not touch the database, you should be able to do Hello World with this.

Below 2019/8/5 postscript

When using Mysql

The above method is just a method of initial setting, and I think that MySQL etc. are often used when actually developing.

	compile("mysql:mysql-connector-java")
	//implementation 'org.hsqldb:hsqldb:2.3.2'

So rewrite build.gradle like this: If nothing is done, an error will occur, so Create a database. I will omit the setup of MYSQL here.

In addition, create a file called ʻapplication.properties in src / main / resouces` and write as follows.


spring.thymeleaf.cache=false
spring.datasource.url=jdbc:mysql://localhost:3306/{My database name}?characterEncoding=UTF-8&serverTimezone=JST

spring.datasource.username={User name}
spring.datasource.password={password}
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.database=MYSQL
spring.jpa.hibernate.ddl-auto=update

Safe, Hello World.

References, etc.


https://qiita.com/aono-masashi/items/a0045d8dc7ea8f106cdf
https://qiita.com/keb/items/c039d00c85fd99c2cee1

Recommended Posts

Until building Spring-Boot using Eclipse on Mac (Gradle version)
Install gradle on mac
[For beginners] Until building a Web application development environment using Java on Mac OS
Install tomcat + eclipse on mac
Until you start nginx on CentOS using Docker on Mac OS
Try using Redmine on Mac docker
I just want to write Java using Eclipse on my Mac
Installed on Lombok Mac (using STS)
Use completion in Eclipse on mac
How to install Eclipse (Photon) on Mac
Download and install Eclipse (Java) (Mac version)
Run jooby's Eclipse development environment on Gradle
Open multiple workspaces in Eclipse on Mac
Eclipse --Springboot
My thoughts on the future [Gradle app version ①]
I tried using Junit on Mac VScode Maven
Install java and android-sdk on Mac using homebrew
Until you start developing android apps on mac
Building a Ruby environment for classes on Mac
Run Edge (Chromium version) on Mac with Selenium
[Note] Struts2 environment construction using Gradle in Eclipse