Skip to content

Commit a230c1f

Browse files
committed
Adds ExceptionHandler Autoconfiguration
1 parent 23f6f65 commit a230c1f

File tree

14 files changed

+220
-20
lines changed

14 files changed

+220
-20
lines changed

build.gradle.kts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
object Versions {
4-
const val KOTLIN_VERSION = "1.4.10"
4+
const val KOTLIN_VERSION = "1.4.30"
55
}
66

77
buildscript {
@@ -18,9 +18,9 @@ plugins {
1818
id("org.sonarqube").version("3.0")
1919
`maven-publish`
2020
id("io.spring.dependency-management") version "1.0.10.RELEASE"
21-
kotlin("jvm").version("1.4.0")
22-
kotlin("plugin.spring").version("1.4.0")
23-
kotlin("kapt").version("1.4.0")
21+
kotlin("jvm").version("1.4.30")
22+
kotlin("plugin.spring").version("1.4.30")
23+
kotlin("kapt").version("1.4.30")
2424
id("java")
2525
id("maven-publish")
2626
id("idea")
@@ -54,7 +54,7 @@ subprojects {
5454
cacheChangingModulesFor(0, "seconds")
5555
}
5656
imports {
57-
mavenBom("org.springframework.boot:spring-boot-dependencies:2.4.2.RELEASE") {
57+
mavenBom("org.springframework.boot:spring-boot-dependencies:2.4.2") {
5858
bomProperty("kotlin.version", Versions.KOTLIN_VERSION)
5959
}
6060
}
@@ -76,7 +76,7 @@ subprojects {
7676
tasks.withType<KotlinCompile> {
7777
kotlinOptions {
7878
freeCompilerArgs = listOf("-Xjsr305=strict")
79-
jvmTarget = "11"
79+
jvmTarget = "15"
8080
}
8181
}
8282

@@ -86,25 +86,28 @@ subprojects {
8686
from(sourceSets["main"].allSource)
8787
}
8888

89-
publishing {
90-
repositories {
91-
92-
}
93-
publications {
94-
create<MavenPublication>(project.name) {
95-
from(components["java"])
96-
artifact(sourcesJarSubProject)
97-
98-
groupId = rootProject.group as? String
99-
artifactId = project.name
100-
version = "${rootProject.version}${project.findProperty("version.appendix") ?: ""}"
89+
if (project.name != "sample") {
90+
println(project.name)
91+
publishing {
92+
repositories {
93+
94+
}
95+
publications {
96+
create<MavenPublication>(project.name) {
97+
from(components["java"])
98+
artifact(sourcesJarSubProject)
99+
100+
groupId = rootProject.group as? String
101+
artifactId = project.name
102+
version = "${rootProject.version}${project.findProperty("version.appendix") ?: ""}"
103+
}
101104
}
102-
}
103105

106+
}
104107
}
105108

106109
configure<JacocoPluginExtension> {
107-
toolVersion = "0.8.5"
110+
toolVersion = "0.8.6"
108111
}
109112

110113
tasks.withType<JacocoReport> {

sample/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id("org.springframework.boot").version("2.4.2")
3+
}
4+
repositories {
5+
mavenCentral()
6+
}
7+
8+
dependencies {
9+
implementation(group = "org.springframework.boot", name = "spring-boot-starter-web")
10+
implementation(project(":spring-json-api-starter"))
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.hndrs.api.sample
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
import org.springframework.boot.runApplication
5+
6+
@SpringBootApplication
7+
open class SampleApplication {
8+
9+
}
10+
11+
fun main(args: Array<String>) {
12+
runApplication<SampleApplication>(*args)
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.hndrs.api.sample
2+
3+
import org.springframework.http.HttpStatus
4+
import org.springframework.web.bind.annotation.GetMapping
5+
import org.springframework.web.bind.annotation.RestController
6+
import org.springframework.web.server.ResponseStatusException
7+
8+
@RestController
9+
class SampleController {
10+
11+
12+
@GetMapping("/test-errors")
13+
fun errors() {
14+
throw ResponseStatusException(HttpStatus.CONFLICT)
15+
}
16+
}

settings.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ project(":spring-json-api").projectDir = File("spring-json-api")
55

66
include("spring-json-api-starter")
77
project(":spring-json-api-starter").projectDir = File("spring-json-api-starter")
8+
9+
include("sample")
10+
project(":sample").projectDir = File("sample")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
dependencies {
2+
implementation(project(":spring-json-api"))
3+
testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-test")
24
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.hndrs.api.autoconfigure
2+
3+
import io.hndrs.api.exception.ExceptionHandler
4+
import org.springframework.context.annotation.Bean
5+
import org.springframework.context.annotation.Configuration
6+
7+
@Configuration
8+
open class JsonApiAutoConfiguration {
9+
10+
@Bean
11+
open fun exceptionAdvice(): ExceptionHandler {
12+
return ExceptionHandler()
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2+
io.hndrs.api.autoconfigure.JsonApiAutoConfiguration
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.hndrs.api.autoconfigure
2+
3+
import io.hndrs.api.exception.ExceptionHandler
4+
import org.junit.jupiter.api.Assertions
5+
import org.junit.jupiter.api.DisplayName
6+
import org.junit.jupiter.api.Test
7+
import org.springframework.boot.autoconfigure.AutoConfigurations
8+
import org.springframework.boot.test.context.runner.WebApplicationContextRunner
9+
10+
@DisplayName("JsonApi Autoconfiguration")
11+
internal class JsonApiAutoConfigurationTest {
12+
13+
@Test
14+
fun test() {
15+
WebApplicationContextRunner()
16+
.withConfiguration(
17+
AutoConfigurations.of(JsonApiAutoConfiguration::class.java)
18+
).run {
19+
Assertions.assertNotNull(it.getBean(ExceptionHandler::class.java))
20+
}
21+
}
22+
}

spring-json-api/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
dependencies {
2+
api(group = "org.springframework.boot", name = "spring-boot-starter-web")
23
}

0 commit comments

Comments
 (0)