Skip to content

Commit

Permalink
add ktlint for spring boot projects (#19)
Browse files Browse the repository at this point in the history
* add ktlint for spring boot projects

* work in progress

* work in progress
  • Loading branch information
khalilou88 authored Jan 2, 2024
1 parent 3cd73e9 commit 42c435f
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 33 deletions.
1 change: 1 addition & 0 deletions nx-gradle/spring-boot/g-sb-kt-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id("io.spring.dependency-management")
kotlin("jvm")
kotlin("plugin.spring")
id("org.jlleitschuh.gradle.ktlint") version "12.0.3"
}

group = "com.example"
Expand Down
12 changes: 12 additions & 0 deletions nx-gradle/spring-boot/g-sb-kt-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
"options": {
"task": "test"
}
},
"ktlint": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "ktlintCheck"
}
},
"ktlint-format": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "ktlintFormat"
}
}
},
"tags": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import org.springframework.web.bind.annotation.RestController
class HelloController(
@Autowired val helloService: HelloService,
) {

@GetMapping("/")
fun greeting():String = helloService.message()

@GetMapping("/")
fun greeting(): String = helloService.message()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ class SpringBootSpringBootKtAppApplication
fun main(args: Array<String>) {
runApplication<SpringBootSpringBootKtAppApplication>(*args)
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import org.springframework.boot.test.web.client.getForEntity
import org.springframework.http.HttpStatus

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class HelloControllerTests(@Autowired val restTemplate: TestRestTemplate) {

class HelloControllerTests(
@Autowired val restTemplate: TestRestTemplate,
) {
@BeforeAll
fun setup() {
println(">> Setup")
Expand All @@ -26,10 +27,8 @@ class HelloControllerTests(@Autowired val restTemplate: TestRestTemplate) {
assertThat(entity.body).contains("Hello World")
}


@AfterAll
fun teardown() {
println(">> Tear down")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class SpringBootSpringBootKtAppApplicationTests {

@Test
fun contextLoads() {
}

@Test
fun contextLoads() {
}
}
13 changes: 7 additions & 6 deletions nx-gradle/spring-boot/g-sb-kt-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val javaVersion: String by project

plugins {
id("org.springframework.boot") apply false
id("io.spring.dependency-management")
id("org.springframework.boot") apply false
id("io.spring.dependency-management")
kotlin("jvm")
kotlin("plugin.spring")
id("org.jlleitschuh.gradle.ktlint") version "12.0.3"
}

group = "com.example"
Expand All @@ -17,13 +18,13 @@ java {
}

repositories {
mavenCentral()
mavenCentral()
}

dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}

dependencies {
Expand Down
12 changes: 12 additions & 0 deletions nx-gradle/spring-boot/g-sb-kt-lib/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
"options": {
"task": "test"
}
},
"ktlint": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "ktlintCheck"
}
},
"ktlint-format": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "ktlintFormat"
}
}
},
"tags": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import org.springframework.stereotype.Service

@Service
class HelloService {

fun message():String {
return "Hello World!"
}
fun message(): String {
return "Hello World!"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest


@SpringBootTest
class HelloServiceTests(@Autowired val helloService: HelloService) {

class HelloServiceTests(
@Autowired val helloService: HelloService,
) {
@BeforeAll
fun setup() {
println(">> Setup")
Expand All @@ -22,11 +22,8 @@ class HelloServiceTests(@Autowired val helloService: HelloService) {
assertThat(helloService.message()).contains("Hello World")
}


@AfterAll
fun teardown() {
println(">> Tear down")
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package com.example.springboot.springbootktlib
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
open class TestConfiguration {
}
open class TestConfiguration

0 comments on commit 42c435f

Please sign in to comment.