Skip to content

Commit

Permalink
Migrate from Java to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Oct 24, 2017
1 parent 2053e9d commit 2d3365f
Show file tree
Hide file tree
Showing 30 changed files with 623 additions and 854 deletions.
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,35 @@
This project is designed to show step by step how to migrate from Java to Kotlin with
Spring Boot.

## [Step 0]((https://github.com/sdeleuze/spring-kotlin-deepdive)): The original Java application
## [Step 1](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step1): Java to Kotlin

* Simple blog with JSON HTTP API
* Demo
* Present the Java application software design
* Reminders:
* No need for annotating constructor when single constructor for autowiring it (as of Spring 4.3), show 2 syntaxes
* `@RequestMapping` aliases: `@GetMapping`, `@PostMapping`, etc.
* Reload via CTRL + F9 in IDEA
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

**[Go to step 1: Java to Kotlin](https://github.com/sdeleuze/spring-kotlin-deepdive/tree/step1)**
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)**
23 changes: 21 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
buildscript {
ext {
kotlinVersion = "1.1.51"
springBootVersion = "1.5.7.RELEASE"
}
repositories {
mavenCentral()
}
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}")
}
}

apply plugin: "java"
apply plugin: "kotlin"
apply plugin: "kotlin-spring"
apply plugin: "kotlin-noarg"
apply plugin: "org.springframework.boot"

group = "io.spring"
version = "1.0.0-SNAPSHOT"
sourceCompatibility = 1.8

repositories {
mavenCentral()
}

noArg {
annotation("org.springframework.data.mongodb.core.mapping.Document")
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

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")
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/io/spring/deepdive/Application.java

This file was deleted.

93 changes: 0 additions & 93 deletions src/main/java/io/spring/deepdive/DatabaseInitializer.java

This file was deleted.

75 changes: 0 additions & 75 deletions src/main/java/io/spring/deepdive/Utils.java

This file was deleted.

Loading

0 comments on commit 2d3365f

Please sign in to comment.