mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
codegen-java/kotlin: Support Spring Boot 3.x instead of 2.x (#729)
Motivation: In Spring Boot 3.0, the annotation type `org.springframework.boot.context.properties.ConstructorBinding` was deprecated in favor of `org.springframework.boot.context.properties.bind.ConstructorBinding`. In 3.2, the old annotation type was removed. As of 3.0, a `@ConstructorBinding` annotation is no longer required/recommended for configuration classes with a single public constructor. Changes: Remove generation of `@ConstructorBinding` annotations in codegen-java and codegen-kotlin. Result: - Generated code is compatible with Spring Boot 3.x. (Verified with locally updated pkl-spring.) - Generated code is no longer compatible with Spring Boot 2.x. To use Pkl 0.27 and later with Spring Boot 2.x, use Pkl 0.26's code generator. - Fixes #139.
This commit is contained in:
@@ -493,10 +493,6 @@ class JavaCodeGenerator(
|
||||
}
|
||||
|
||||
fun generateSpringBootAnnotations(builder: TypeSpec.Builder) {
|
||||
builder.addAnnotation(
|
||||
ClassName.get("org.springframework.boot.context.properties", "ConstructorBinding")
|
||||
)
|
||||
|
||||
if (isModuleClass) {
|
||||
builder.addAnnotation(
|
||||
ClassName.get("org.springframework.boot.context.properties", "ConfigurationProperties")
|
||||
|
||||
@@ -1484,7 +1484,6 @@ class JavaCodeGeneratorTest {
|
||||
assertThat(javaCode)
|
||||
.contains(
|
||||
"""
|
||||
|@ConstructorBinding
|
||||
|@ConfigurationProperties
|
||||
|public final class Mod {
|
||||
"""
|
||||
@@ -1498,7 +1497,6 @@ class JavaCodeGeneratorTest {
|
||||
)
|
||||
.contains(
|
||||
"""
|
||||
| @ConstructorBinding
|
||||
| @ConfigurationProperties("server")
|
||||
| public static final class Server {
|
||||
"""
|
||||
@@ -1512,13 +1510,12 @@ class JavaCodeGeneratorTest {
|
||||
"""
|
||||
.trimMargin()
|
||||
)
|
||||
.doesNotContain("@ConstructorBinding")
|
||||
|
||||
// not worthwhile to add spring & spring boot dependency just so that this test can compile
|
||||
// their annotations
|
||||
val javaCodeWithoutSpringAnnotations =
|
||||
javaCode.deleteLines {
|
||||
it.contains("ConstructorBinding") || it.contains("ConfigurationProperties")
|
||||
}
|
||||
javaCode.deleteLines { it.contains("ConfigurationProperties") }
|
||||
assertThat(javaCodeWithoutSpringAnnotations).compilesSuccessfully()
|
||||
}
|
||||
|
||||
|
||||
@@ -449,10 +449,6 @@ class KotlinCodeGenerator(
|
||||
}
|
||||
|
||||
fun generateSpringBootAnnotations(builder: TypeSpec.Builder) {
|
||||
builder.addAnnotation(
|
||||
ClassName("org.springframework.boot.context.properties", "ConstructorBinding")
|
||||
)
|
||||
|
||||
if (isModuleClass) {
|
||||
builder.addAnnotation(
|
||||
ClassName("org.springframework.boot.context.properties", "ConfigurationProperties")
|
||||
|
||||
@@ -1427,7 +1427,6 @@ class KotlinCodeGeneratorTest {
|
||||
assertThat(kotlinCode)
|
||||
.contains(
|
||||
"""
|
||||
|@ConstructorBinding
|
||||
|@ConfigurationProperties
|
||||
|data class Mod(
|
||||
| val server: Server
|
||||
@@ -1436,7 +1435,6 @@ class KotlinCodeGeneratorTest {
|
||||
)
|
||||
.contains(
|
||||
"""
|
||||
| @ConstructorBinding
|
||||
| @ConfigurationProperties("server")
|
||||
| data class Server(
|
||||
| val port: Long,
|
||||
@@ -1444,13 +1442,12 @@ class KotlinCodeGeneratorTest {
|
||||
"""
|
||||
.trimMargin()
|
||||
)
|
||||
.doesNotContain("@ConstructorBinding")
|
||||
|
||||
// not worthwhile to add spring & spring boot dependency just so that this test can compile
|
||||
// their annotations
|
||||
val kotlinCodeWithoutSpringAnnotations =
|
||||
kotlinCode.deleteLines {
|
||||
it.contains("ConstructorBinding") || it.contains("ConfigurationProperties")
|
||||
}
|
||||
kotlinCode.deleteLines { it.contains("ConfigurationProperties") }
|
||||
assertThat(kotlinCodeWithoutSpringAnnotations).compilesSuccessfully()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user