Hi, this is @chan_kaku This time, Spring Boot 1.5 series will become EOL in August of this year, so I would like to try to deal with it and mention the difficult points.
Spring Boot is a framework that makes it easy to create applications based on the Spring framework. See the official documentation (https://spring.io/projects/spring-boot) for more information.
--Gradle3 series → Gradle5 series --SpringBoot 1.5 series → SpringBoot 2.1 series --Upgrade of other dependent libraries
First of all, in order to raise it to SpringBoot2 series, I had to raise the version of Gradle to 4.4 or higher, so I worked on it from here Since the target project used Gradle Wrapper was used, I modified gradle-wrapper.properties as follows.
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip #I changed the version here
With the above support, Spring Boot 2 system can finally be used, so I will raise the version here. The basics can be found on the Spring Boot Github Wiki at here. please
build.gradle
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
It was not boot1.5 series, but according to Document, it seems that I had to add ʻio.spring.dependency-management`.
In Gradle3 series, Java and Spring Boot were also described as follows.
build.gradle
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
However, from the Gradle 5 series, the writing method has changed and it is now recommended to write as a block as follows.
build.gradle
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'java'
}
The way dependencies are written has also changed significantly. The writing style up to Gradle 3 series is like this.
build.gradle
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')
//.....etc
Basically, the dependent library was written by compile.
However, in Gradle 5 series, the writing style of ʻimplementation is increasing, and
compileis deprecated. The difference between
compile and ʻimplementation
is simply the extent of dependency propagation.
Therefore, I replaced the part written as compile
with ʻimplementation` as shown below.
build.gradle
implementaion('org.springframework.boot:spring-boot-starter')
implementaion('org.springframework.boot:spring-boot-starter-web')
//.....etc
This was also changed a little. Official documentation
I used to write like this
build.gradle
jar {
baseName = "hoge"
archiveName = "${baseName}.jar"
version = "1.0.0-SNAPSHOT"
}
Of these, baseName
and ʻarchiveName` were deprecated, so I modified them as follows according to Document.
build.gradle
jar {
archiveBaseName = "hoge"
archiveFileName = "${archiveBaseName}.jar"
version = "1.0.0-SNAPSHOT"
}
baseName
goes to ʻarchiveBaseName It seems that ʻarchiveName
has been changed to ʻarchiveFileName In addition to this, ʻappendix
etc. have been changed, so please have a look at the Document! !!
Doma2 was used for DB access of the project upgraded this time. In the original dependencies, I wrote as follows.
build.gradle
compile('org.seasar.doma.boot:doma-spring-boot-starter:1.1.0')
As you can see in the above way of writing dependencies, I simply replaced compile
with ʻimplementation` and it got stuck in an unexpected place.
I got an error saying that I can't DI because Dao's Bean is not registered in the class I'm DI
I couldn't figure out the cause for a while, but once I looked at the document of doma2, there was a difference from the original build.gradle, so
I made the following changes and it worked fine for Dao's Bean registration!
build.gradle
implementation('org.seasar.doma.boot:doma-spring-boot-starter:1.1.1')
implementation("org.seasar.doma:doma:2.24.0")
annotationProcessor("org.seasar.doma:doma:2.24.0")
Until now, it worked only with doma-spring-boot-starter
at the top, but I had to add'doma'itself with implement metaion.
It seemed that I had to put in doma
using ʻannotation Processor This annotationProcessor
was added from the Gradle 5 series, and the reason why it has to be added is that the Gradle 5 series does not support the method of getting the annotation processor from the classpath at compile time. ..
Therefore, if you are using not only doma but also a library that used to get the annotation processor from the classpath, you have to add ʻannotation Processor` like this.
jackson is a Java library for processing JSON format data, which was used in this project.
As in the example, when I simply replaced compile
with ʻimplementaion`, I got an error about bean registration in the jackson library as in doma2.
This could be solved by updating the version.
This time, in order to measure how difficult this migration is, I tried to target a project with as few dependent libraries as possible. However, there were more addictions than I had expected, and it was a difficult impression for me personally. Since the 1.5 series EOL is said to be in August of this year, we recommend that you move as soon as possible! I hope you find this article helpful.
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide https://qiita.com/yukina-ge/items/1ca029ed69494bfd36d6 https://qiita.com/opengl-8080/items/6ad642e0b016465891de https://doma.readthedocs.io/en/2.19.2/build/
Recommended Posts