Polish "Add jackson-module-kotlin dependency when appropriate"

Closes gh-600
This commit is contained in:
Stephane Nicoll
2018-02-12 15:14:25 +01:00
parent 4d0fac5df0
commit 15fb6eb1c2
2 changed files with 29 additions and 11 deletions

View File

@@ -25,8 +25,7 @@ import org.springframework.stereotype.Component;
/**
* A {@link ProjectRequestPostProcessor} that automatically adds "jackson-module-kotlin"
* when Kotlin is used and a dependency has the "json" facet (meaning that it has
* "spring-boot-starter-json" transitive dependency).
* when Kotlin is used and a dependency has the "json" facet.
*
* @author Sebastien Deleuze
*/
@@ -36,13 +35,15 @@ class JacksonKotlinRequestPostProcessor implements ProjectRequestPostProcessor {
private final Dependency jacksonModuleKotlin;
public JacksonKotlinRequestPostProcessor() {
this.jacksonModuleKotlin = Dependency.withId(
"jackson-module-kotlin", "com.fasterxml.jackson.module", "jackson-module-kotlin");
this.jacksonModuleKotlin = Dependency.withId("jackson-module-kotlin",
"com.fasterxml.jackson.module", "jackson-module-kotlin");
}
@Override
public void postProcessAfterResolution(ProjectRequest request, InitializrMetadata metadata) {
if (request.getFacets().contains("json") && "kotlin".equals(request.getLanguage())) {
public void postProcessAfterResolution(ProjectRequest request,
InitializrMetadata metadata) {
if (request.getFacets().contains("json")
&& "kotlin".equals(request.getLanguage())) {
request.getResolvedDependencies().add(this.jacksonModuleKotlin);
}
}

View File

@@ -24,19 +24,29 @@ import org.junit.Test;
* Tests for {@link JacksonKotlinRequestPostProcessor}.
*
* @author Sebastien Deleuze
* @author Stephane Nicoll
*/
public class JacksonKotlinRequestPostProcessorTests
extends AbstractRequestPostProcessorTests {
static final Dependency JACKSON_KOTLIN = Dependency.withId("jackson-module-kotlin",
"com.fasterxml.jackson.module", "jackson-module-kotlin");
static final Dependency REACTOR_TEST = Dependency.create(
"io.projectreactor", "reactor-test", null, Dependency.SCOPE_TEST);
@Test
public void jacksonModuleKotlinIsAdded() {
ProjectRequest request = createProjectRequest("webflux");
request.setBootVersion("2.0.0.M2");
request.setLanguage("kotlin");
Dependency jacksonKotlinModuleTest = Dependency.withId(
"jackson-module-kotlin", "com.fasterxml.jackson.module", "jackson-module-kotlin");
generateMavenPom(request)
.hasDependency(jacksonKotlinModuleTest)
.hasSpringBootStarterDependency("webflux")
.hasDependency(JACKSON_KOTLIN)
.hasSpringBootStarterTest()
.hasDependency(REACTOR_TEST)
.hasDependency("org.jetbrains.kotlin", "kotlin-reflect")
.hasDependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
.hasDependenciesCount(6);
}
@@ -45,16 +55,23 @@ public class JacksonKotlinRequestPostProcessorTests
ProjectRequest request = createProjectRequest("webflux");
request.setBootVersion("2.0.0.M2");
generateMavenPom(request)
.hasSpringBootStarterDependency("webflux")
.hasSpringBootStarterTest()
.hasDependency(REACTOR_TEST)
.hasDependenciesCount(3);
}
@Test
public void jacksonModuleKotlinIsNotAddedWithoutJsonFacet() {
ProjectRequest request = createProjectRequest("batch");
ProjectRequest request = createProjectRequest("actuator");
request.setBootVersion("2.0.0.M2");
request.setLanguage("kotlin");
generateMavenPom(request)
.hasDependenciesCount(5);
.hasSpringBootStarterDependency("actuator")
.hasSpringBootStarterTest()
.hasDependency("org.jetbrains.kotlin", "kotlin-reflect")
.hasDependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
.hasDependenciesCount(4);
}
}