mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Add KSP2 testing
This commit is contained in:
@@ -11,19 +11,27 @@ plugins {
|
|||||||
|
|
||||||
tasks.withType<KotlinCompile>().configureEach {
|
tasks.withType<KotlinCompile>().configureEach {
|
||||||
compilerOptions {
|
compilerOptions {
|
||||||
freeCompilerArgs.addAll(
|
optIn.addAll(
|
||||||
"-opt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview",
|
"com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview",
|
||||||
"-opt-in=com.squareup.moshi.kotlin.codegen.api.InternalMoshiCodegenApi",
|
"com.squareup.moshi.kotlin.codegen.api.InternalMoshiCodegenApi",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.compileTestKotlin {
|
tasks.compileTestKotlin {
|
||||||
compilerOptions {
|
compilerOptions {
|
||||||
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
|
optIn.add("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
// KSP2 needs more memory to run until 1.0.21
|
||||||
|
minHeapSize = "2048m"
|
||||||
|
maxHeapSize = "2048m"
|
||||||
|
// Disable the annoying GradleWorkerMain apps that pop up while running
|
||||||
|
jvmArgs("-Djava.awt.headless=true")
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":moshi"))
|
implementation(project(":moshi"))
|
||||||
api(libs.kotlinpoet)
|
api(libs.kotlinpoet)
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
package com.squareup.moshi.kotlin.codegen.ksp
|
package com.squareup.moshi.kotlin.codegen.ksp
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
|
|
||||||
import com.squareup.moshi.JsonAdapter
|
import com.squareup.moshi.JsonAdapter
|
||||||
import com.squareup.moshi.JsonReader
|
import com.squareup.moshi.JsonReader
|
||||||
import com.squareup.moshi.kotlin.codegen.api.Options.OPTION_GENERATED
|
import com.squareup.moshi.kotlin.codegen.api.Options.OPTION_GENERATED
|
||||||
@@ -27,11 +26,8 @@ import com.tschuchort.compiletesting.SourceFile
|
|||||||
import com.tschuchort.compiletesting.SourceFile.Companion.java
|
import com.tschuchort.compiletesting.SourceFile.Companion.java
|
||||||
import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
|
import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
|
||||||
import com.tschuchort.compiletesting.configureKsp
|
import com.tschuchort.compiletesting.configureKsp
|
||||||
import com.tschuchort.compiletesting.kspIncremental
|
|
||||||
import com.tschuchort.compiletesting.kspProcessorOptions
|
import com.tschuchort.compiletesting.kspProcessorOptions
|
||||||
import com.tschuchort.compiletesting.kspSourcesDir
|
import com.tschuchort.compiletesting.kspSourcesDir
|
||||||
import com.tschuchort.compiletesting.kspWithCompilation
|
|
||||||
import com.tschuchort.compiletesting.symbolProcessorProviders
|
|
||||||
import kotlin.reflect.KTypeProjection
|
import kotlin.reflect.KTypeProjection
|
||||||
import kotlin.reflect.full.createType
|
import kotlin.reflect.full.createType
|
||||||
import kotlin.reflect.full.declaredMemberProperties
|
import kotlin.reflect.full.declaredMemberProperties
|
||||||
@@ -40,9 +36,21 @@ import org.junit.Ignore
|
|||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.runners.Parameterized
|
||||||
|
|
||||||
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
||||||
class JsonClassSymbolProcessorTest {
|
@RunWith(Parameterized::class)
|
||||||
|
class JsonClassSymbolProcessorTest(private val useKSP2: Boolean) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
@Parameterized.Parameters(name = "useKSP2={0}")
|
||||||
|
fun data(): Collection<Array<Any>> = listOf(
|
||||||
|
arrayOf(false),
|
||||||
|
arrayOf(true),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@JvmField
|
@JvmField
|
||||||
@@ -852,12 +860,10 @@ class JsonClassSymbolProcessorTest {
|
|||||||
inheritClassPath = true
|
inheritClassPath = true
|
||||||
sources = sourceFiles.asList()
|
sources = sourceFiles.asList()
|
||||||
verbose = false
|
verbose = false
|
||||||
// TODO parameterize this
|
configureKsp(useKsp2 = useKSP2) {
|
||||||
val useKsp2 = false
|
|
||||||
configureKsp(useKsp2 = useKsp2) {
|
|
||||||
symbolProcessorProviders += JsonClassSymbolProcessorProvider()
|
symbolProcessorProviders += JsonClassSymbolProcessorProvider()
|
||||||
incremental = true // The default now
|
incremental = true // The default now
|
||||||
if (!useKsp2) {
|
if (!useKSP2) {
|
||||||
withCompilation = true // Only necessary for KSP1
|
withCompilation = true // Only necessary for KSP1
|
||||||
languageVersion = "1.9"
|
languageVersion = "1.9"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user