mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-02 11:24:04 +08:00
Polish "Add jackson-module-kotlin dependency when appropriate"
Closes gh-600
This commit is contained in:
@@ -25,8 +25,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ProjectRequestPostProcessor} that automatically adds "jackson-module-kotlin"
|
* A {@link ProjectRequestPostProcessor} that automatically adds "jackson-module-kotlin"
|
||||||
* when Kotlin is used and a dependency has the "json" facet (meaning that it has
|
* when Kotlin is used and a dependency has the "json" facet.
|
||||||
* "spring-boot-starter-json" transitive dependency).
|
|
||||||
*
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
@@ -36,13 +35,15 @@ class JacksonKotlinRequestPostProcessor implements ProjectRequestPostProcessor {
|
|||||||
private final Dependency jacksonModuleKotlin;
|
private final Dependency jacksonModuleKotlin;
|
||||||
|
|
||||||
public JacksonKotlinRequestPostProcessor() {
|
public JacksonKotlinRequestPostProcessor() {
|
||||||
this.jacksonModuleKotlin = Dependency.withId(
|
this.jacksonModuleKotlin = Dependency.withId("jackson-module-kotlin",
|
||||||
"jackson-module-kotlin", "com.fasterxml.jackson.module", "jackson-module-kotlin");
|
"com.fasterxml.jackson.module", "jackson-module-kotlin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessAfterResolution(ProjectRequest request, InitializrMetadata metadata) {
|
public void postProcessAfterResolution(ProjectRequest request,
|
||||||
if (request.getFacets().contains("json") && "kotlin".equals(request.getLanguage())) {
|
InitializrMetadata metadata) {
|
||||||
|
if (request.getFacets().contains("json")
|
||||||
|
&& "kotlin".equals(request.getLanguage())) {
|
||||||
request.getResolvedDependencies().add(this.jacksonModuleKotlin);
|
request.getResolvedDependencies().add(this.jacksonModuleKotlin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,19 +24,29 @@ import org.junit.Test;
|
|||||||
* Tests for {@link JacksonKotlinRequestPostProcessor}.
|
* Tests for {@link JacksonKotlinRequestPostProcessor}.
|
||||||
*
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class JacksonKotlinRequestPostProcessorTests
|
public class JacksonKotlinRequestPostProcessorTests
|
||||||
extends AbstractRequestPostProcessorTests {
|
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
|
@Test
|
||||||
public void jacksonModuleKotlinIsAdded() {
|
public void jacksonModuleKotlinIsAdded() {
|
||||||
ProjectRequest request = createProjectRequest("webflux");
|
ProjectRequest request = createProjectRequest("webflux");
|
||||||
request.setBootVersion("2.0.0.M2");
|
request.setBootVersion("2.0.0.M2");
|
||||||
request.setLanguage("kotlin");
|
request.setLanguage("kotlin");
|
||||||
Dependency jacksonKotlinModuleTest = Dependency.withId(
|
|
||||||
"jackson-module-kotlin", "com.fasterxml.jackson.module", "jackson-module-kotlin");
|
|
||||||
generateMavenPom(request)
|
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);
|
.hasDependenciesCount(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,16 +55,23 @@ public class JacksonKotlinRequestPostProcessorTests
|
|||||||
ProjectRequest request = createProjectRequest("webflux");
|
ProjectRequest request = createProjectRequest("webflux");
|
||||||
request.setBootVersion("2.0.0.M2");
|
request.setBootVersion("2.0.0.M2");
|
||||||
generateMavenPom(request)
|
generateMavenPom(request)
|
||||||
|
.hasSpringBootStarterDependency("webflux")
|
||||||
|
.hasSpringBootStarterTest()
|
||||||
|
.hasDependency(REACTOR_TEST)
|
||||||
.hasDependenciesCount(3);
|
.hasDependenciesCount(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jacksonModuleKotlinIsNotAddedWithoutJsonFacet() {
|
public void jacksonModuleKotlinIsNotAddedWithoutJsonFacet() {
|
||||||
ProjectRequest request = createProjectRequest("batch");
|
ProjectRequest request = createProjectRequest("actuator");
|
||||||
request.setBootVersion("2.0.0.M2");
|
request.setBootVersion("2.0.0.M2");
|
||||||
request.setLanguage("kotlin");
|
request.setLanguage("kotlin");
|
||||||
generateMavenPom(request)
|
generateMavenPom(request)
|
||||||
.hasDependenciesCount(5);
|
.hasSpringBootStarterDependency("actuator")
|
||||||
|
.hasSpringBootStarterTest()
|
||||||
|
.hasDependency("org.jetbrains.kotlin", "kotlin-reflect")
|
||||||
|
.hasDependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
|
||||||
|
.hasDependenciesCount(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user