Kotlin – How to start Kotlin development with SpringBoot + Maven + SpringToolSuite

In the tutorial, JavaSampleApproach will help you with the first step for starting development with Spring Kotlin language by building a Kotlin HelloWorld example using SpringBoot, Maven and SpringToolSuite.

Related posts:
Kotlin – How to build a SpringBoot Kotlin RESTful Web Service with @RestController
Kotlin Spring MVC RequestMapping RESTful APIs with @GetMapping, @PostMapping, @PutMapping, @DeleteMapping | SpringBoot Example

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.6.RELEASE
– Kotlin language

II. Practice

Step to do:
– Create SpringBoot project with Kotlin language
– Install Kotlin Plugin for Eclipse
– Run and check results

1. Create SpringBoot project with Kotlin language

Open SpringToolSuite, choose File -> New -> Other -> Spring Starter Project:

springboot kotlin helloworld - spring starter project

Press Next, then input project info as below image:

springboot kotlin helloworld - input project infor

Press Next -> Finish, we got:

springboot kotlin helloworld - project structure

Take a look at pom.xml file:



	4.0.0

	com.javasampleapproach.kotlin
	SpringKotlinHelloWorld
	0.0.1
	jar

	SpringKotlinHelloWorld
	SpringKotlinHelloWorld

	
		org.springframework.boot
		spring-boot-starter-parent
		1.5.6.RELEASE
		 
	

	
		true
		UTF-8
		UTF-8
		1.8
		1.1.4
	

	
		
			org.springframework.boot
			spring-boot-starter
		
		
			org.jetbrains.kotlin
			kotlin-stdlib-jre8
			${kotlin.version}
		
		
			org.jetbrains.kotlin
			kotlin-reflect
			${kotlin.version}
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		${project.basedir}/src/main/kotlin
		${project.basedir}/src/test/kotlin
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
			
				kotlin-maven-plugin
				org.jetbrains.kotlin
				${kotlin.version}
				
					
						spring
					
					1.8
				
				
					
						compile
						compile
						
							compile
						
					
					
						test-compile
						test-compile
						
							test-compile
						
					
				
				
					
						org.jetbrains.kotlin
						kotlin-maven-allopen
						${kotlin.version}
					
				
			
		
	



2. Install Kotlin Plugin for Eclipse

What is Kotlin Plugin for Eclipse?
-> The Kotlin Plugin for Eclipse helps you write, run, debug and test programs in Kotlin language.

How to install it?

On main Menu, choose Help -> Install New Software….
Add kotlin plugin for eclipse with link: https://dl.bintray.com/jetbrains/kotlin/eclipse-plugin/last/

springboot kotlin helloworld - add kotlin plugin for eclipse

We got:

springboot kotlin helloworld - add kotlin plugin for eclipse - we got

Check Kotlin as above image, then press Next.
Now follow the guides to install Kotlin plugin. After all is Done, we will get a Software Update message dialog.

springboot kotlin helloworld - restart notified for effect updates

Press Yes to restart SpringToolSuite for the changes to take effect.
-> Result:

springboot kotlin helloworld - project structure - updated

3. Run and check results

Open class SpringKotlinHelloWorldApplication, then add some println line of codes as below:

package com.javasampleapproach.kotlin

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class SpringKotlinHelloWorldApplication

fun main(args: Array) {
    SpringApplication.run(SpringKotlinHelloWorldApplication::class.java, *args)
	println("#########################       Kotlination.com            #########################")
	println("#########################        Hello, world!             #########################")
	println("#########################       Have a nice day!           #########################")
}

Build the project with commandline mvn clean install -Dmaven.test.skip=true:

springboot kotlin helloworld - build kotlin project
Run the Kotlin SpringBoot project with commandline mvn spring-boot:run.
-> Results:

spring kotlin helloworld - run results

III. Sourcecode

SpringKotlinHelloWorld

One thought on “Kotlin – How to start Kotlin development with SpringBoot + Maven + SpringToolSuite”

Leave a Reply

Your email address will not be published. Required fields are marked *