Skip to content

Commit c369a8f

Browse files
committed
feat: add API validation support in CommonSurfExtension and CommonSurfPlugin
1 parent 789102d commit c369a8f

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfExtension.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ abstract class CommonSurfExtension(protected val objects: ObjectFactory) {
1919
internal val withSurfDatabaseR2dbc = objects.property<Boolean>().convention(false)
2020
internal val surfDatabaseR2dbcVersion = objects.property<String>()
2121
internal val surfDatabaseR2dbcRelocation = objects.property<String>()
22+
internal val withApiValidation = objects.property<Boolean>().convention(false)
23+
24+
fun withApiValidation() {
25+
withApiValidation.set(true)
26+
withApiValidation.finalizeValue()
27+
}
2228

2329
fun withSurfRedis() {
2430
withSurfRedis.set(true)

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfPlugin.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
2525
protected val platformName: String,
2626
private val platform: SurfApiPlatform,
2727
) : Plugin<Project> {
28-
private var apiValidation: Boolean = false
29-
3028
private val commonPlugins = listOf(
3129
"org.gradle.java-gradle-plugin",
3230
"org.gradle.java-library",
@@ -195,10 +193,6 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
195193
configure0()
196194
}
197195

198-
fun Project.withApiValidation(value: Boolean = true) {
199-
apiValidation = value
200-
}
201-
202196
private fun Project.configureAllOpen() = configure<AllOpenExtension> {
203197
annotation("jakarta.persistence.Entity")
204198
annotation("jakarta.persistence.MappedSuperclass")
@@ -210,13 +204,6 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
210204
compilerOptions {
211205
freeCompilerArgs.addAll(listOf("-Xjsr305=strict"))
212206
}
213-
214-
@OptIn(ExperimentalAbiValidation::class)
215-
if (apiValidation) {
216-
configure<AbiValidationExtension> {
217-
enabled.set(true)
218-
}
219-
}
220207
}
221208

222209
private fun Project.configureAutoService() = dependencies {
@@ -276,6 +263,15 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
276263
}
277264
}
278265

266+
if (extension.withApiValidation.get()) {
267+
configure<KotlinJvmProjectExtension> {
268+
@OptIn(ExperimentalAbiValidation::class)
269+
configure<AbiValidationExtension> {
270+
enabled.set(true)
271+
}
272+
}
273+
}
274+
279275
afterEvaluated0(extension)
280276
}
281277

0 commit comments

Comments
 (0)