Code Spring Boot Project With Kotlin by Android Studio

Step 1

Modify build.gradle

  1. In Module Dir : apply plugin: ‘kotlin’ and add kotlin dependencies
1
2
3
4
5
6
7
8
9
10
11
apply plugin: 'org.springframework.boot'
apply plugin: 'java'
apply plugin: 'kotlin'//notice


dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
compile 'org.springframework.boot:spring-boot-starter:2.3.4.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:2.3.4.RELEASE'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72"//notice
}
  1. Project Dir : add kotlin classpath
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"//notice
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

Step 2

  1. Code with kotlin

    tip: if you use pure kotlin, you may code in kotlin dir replace java

Step 3

Done!

本文为作者原创 转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

0%