-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
227 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,25 @@ | ||
# Spring Kotlin deepdive | ||
|
||
This project is designed to show step by step how to migrate from Java to Kotlin with | ||
Spring Boot. | ||
Spring Boot step by step: | ||
* [Step 0](https://github.com/sdeleuze/spring-kotlin-deepdive/): Initial Java project | ||
* [Step 1](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step1): Java to Kotlin | ||
* [Step 2](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step2): Spring Boot 2 | ||
* [Step 3](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step3): Spring WebFlux | ||
* [Step 4](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step4): Kotlin routing DSL | ||
|
||
See [Spring Kotlin support documentation](https://docs.spring.io/spring/docs/current/spring-framework-reference/languages.html#kotlin) for more details. | ||
|
||
## Step 2: Spring Boot 2 | ||
|
||
## [Step 1](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step1): Java to Kotlin | ||
* Spring Data Kay | ||
* No need for `kotlin-noarg` plugin since it supports natively Kotlin immutable classes | ||
* Spring Boot 2 | ||
* `jackson-module-kotlin` and `jackson-datatype-jsr310` provided by default with Jackson starter | ||
* Mustache suffix is already `.mustache` by default | ||
* Null safety | ||
* `@RequestParam` on nullable parameter | ||
* Extensions | ||
* JUnit 5 + `@BeforeAll`/ `@AfterAll` | ||
|
||
Code: | ||
* No more semicolon at end of lines | ||
* Type suffixed with colon, as statically typed as Java, optional type inference | ||
* Show how to configure return type inference hints | ||
* Short syntax for declaring properties and initializing them from the primary constructor instead of super verbose mostly auto-generated POJO | ||
* [Data classes](https://kotlinlang.org/docs/reference/data-classes.html) | ||
* Syntax help using naturally immutable classes | ||
* `:` instead of `extends` | ||
* No need for `{ }` for empty classes / interfaces | ||
* `public` by the default | ||
* `fun` to declare functions | ||
* Better lambdas: `{ }` last parameter notation, lambda without collect, `it` default parameter | ||
* Constructor without `new` | ||
* `main()` top level method | ||
* `Utils` class -> [Kotlin extensions](https://kotlinlang.org/docs/reference/extensions.html) | ||
* `.getBody()` -> `.body` | ||
* Meaningful function names between backticks | ||
|
||
Build: | ||
* Dependencies: | ||
* `kotlin-stdlib-jre8` | ||
* `kotlin-reflect` | ||
* `jackson-module-kotlin` | ||
* Plugins: | ||
* `kotlin` | ||
* `kotlin-spring` | ||
* `kotlin-noarg` | ||
* Configure to build Java 8 bytecode | ||
|
||
**[Go to step 2: Spring Boot 2](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step2)** | ||
**[Go to step 3: Spring WebFlux](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step3)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,63 @@ | ||
buildscript { | ||
ext { | ||
kotlinVersion = "1.1.51" | ||
springBootVersion = "1.5.7.RELEASE" | ||
springBootVersion = "2.0.0.M5" | ||
} | ||
repositories { | ||
mavenCentral() | ||
maven { url "https://repo.spring.io/milestone" } | ||
maven { url "https://repo.spring.io/snapshot" } | ||
} | ||
dependencies { | ||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") | ||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") | ||
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}") | ||
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}") | ||
classpath("org.junit.platform:junit-platform-gradle-plugin:1.0.1") | ||
} | ||
} | ||
|
||
apply plugin: "kotlin" | ||
apply plugin: "kotlin-spring" | ||
apply plugin: "kotlin-noarg" | ||
apply plugin: "org.springframework.boot" | ||
apply plugin: "io.spring.dependency-management" | ||
apply plugin: "org.junit.platform.gradle.plugin" | ||
|
||
group = "io.spring" | ||
version = "1.0.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
noArg { | ||
annotation("org.springframework.data.mongodb.core.mapping.Document") | ||
maven { url "https://repo.spring.io/milestone" } | ||
maven { url "https://repo.spring.io/snapshot" } | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
freeCompilerArgs = ["-Xjsr305=strict"] | ||
} | ||
} | ||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
freeCompilerArgs = ["-Xjsr305=strict"] | ||
} | ||
} | ||
|
||
dependencies { | ||
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8") | ||
compile("org.jetbrains.kotlin:kotlin-reflect") | ||
compile("com.fasterxml.jackson.module:jackson-module-kotlin") | ||
compile("org.springframework.boot:spring-boot-starter-actuator") | ||
compile("org.springframework.boot:spring-boot-starter-data-mongodb") | ||
compile("org.springframework.boot:spring-boot-starter-web") | ||
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") | ||
compile("org.springframework.boot:spring-boot-starter-mustache") | ||
compile("com.atlassian.commonmark:commonmark:0.10.0") | ||
compile("com.atlassian.commonmark:commonmark-ext-autolink:0.10.0") | ||
compile("de.flapdoodle.embed:de.flapdoodle.embed.mongo") | ||
runtime("org.springframework.boot:spring-boot-devtools") | ||
testCompile("org.springframework.boot:spring-boot-starter-test") | ||
testCompile("org.springframework.boot:spring-boot-starter-test") { | ||
exclude module: "junit" | ||
} | ||
testCompile("org.junit.jupiter:junit-jupiter-api") | ||
testRuntime("org.junit.jupiter:junit-jupiter-engine") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.