Skip to content

Commit

Permalink
Update to K2 (#89)
Browse files Browse the repository at this point in the history
* Update deps + add more ksp2 deps

* Set up KSP2 test infra

* Update test for KSP2 testing

* Enable CC

* Add .kotlin to ignored

* Update to KCT alpha03

* beta4

* Update KCT

* Update name

* Spotless

* Beta5

* RC1

* Really though?

* one of these should do it

* RC2

* RC2

* S

* RC3

* KSP rc3

* 2.0 final

* Spotless

* Update API

* final
  • Loading branch information
ZacSweers committed Jun 7, 2024
1 parent 02c68fb commit 5b4b585
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 35 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
name: CI

on: [push, pull_request]
on:
# Only run push on main
push:
branches:
- main
paths-ignore:
- '**/*.md'
# Always run on PRs
pull_request:
branches: [ main ]

concurrency:
group: 'ci-${{ github.event.merge_group.head_ref || github.head_ref }}-${{ github.workflow }}'
cancel-in-progress: true

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gen/
.gradle/
.gradletasknamecache
build/
.kotlin/

# Local configuration file (sdk path, etc)
local.properties
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
org.gradle.jvmargs=-Xms1g -Xmx4g -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError

GROUP=dev.zacsweers.autoservice
VERSION_NAME=1.2.0-SNAPSHOT
Expand All @@ -30,5 +31,9 @@ SONATYPE_STAGING_PROFILE=dev.zacsweers

org.gradle.configureondemand=true
kapt.include.compile.classpath=false
org.gradle.configuration-cache=true

ksp.version.check=false

# Use KSP2
ksp.useKSP2=true
9 changes: 4 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[versions]
autoService = "1.1.1"
kct = "0.4.1"
kotlin = "1.9.24"
kct = "0.5.0"
kotlin = "2.0.0"
jdk = "21"
jvmTarget = "11"
kotlinpoet = "1.17.0"
ksp = "1.9.24-1.0.20"
ksp = "2.0.0-1.0.22"
ktfmt = "0.50"

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.14.0" }
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.15.0-Beta.2" }
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.28.0" }
Expand All @@ -28,7 +28,6 @@ kotlin-compilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-emb
kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" }
kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" }

ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }

# Only present to trigger automatic renovate updates
Expand Down
13 changes: 9 additions & 4 deletions processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ plugins {
alias(libs.plugins.mavenPublish)
}

tasks.test {
// KSP2 needs more memory to run
minHeapSize = "1024m"
maxHeapSize = "1024m"
}

dependencies {
ksp(libs.autoService.ksp)
compileOnly(libs.ksp.api)
Expand All @@ -28,12 +34,11 @@ dependencies {
implementation(libs.kotlinpoet)
implementation(libs.guava)

testImplementation(libs.ksp.api)
testImplementation(libs.truth)
testImplementation(libs.junit)
testImplementation(libs.kotlin.compilerEmbeddable)
testImplementation(libs.kct.core)
testImplementation(libs.ksp)
testImplementation(libs.kct.ksp)
testImplementation(libs.kotlin.compilerEmbeddable)
testImplementation(libs.ksp.api)
testImplementation(libs.truth)
testImplementation(libs.kotlinpoet.ksp)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,46 @@ import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.KotlinCompilation.ExitCode
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
import com.tschuchort.compiletesting.configureKsp
import com.tschuchort.compiletesting.kspIncremental
import com.tschuchort.compiletesting.kspSourcesDir
import com.tschuchort.compiletesting.symbolProcessorProviders
import com.tschuchort.compiletesting.useKsp2
import java.io.File
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

@OptIn(ExperimentalCompilerApi::class)
@RunWith(Parameterized::class)
class AutoServiceSymbolProcessorTest(private val incremental: Boolean) {
class AutoServiceSymbolProcessorTest(
private val incremental: Boolean,
private val useKSP2: Boolean,
) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "incremental={0}")
@Parameters(name = "incremental={0},useKSP2={1}")
fun data(): Collection<Array<Any>> {
return listOf(arrayOf(true), arrayOf(false))
return listOf(arrayOf(true, false), arrayOf(false, true))
}
}

private fun newCompilation(): KotlinCompilation {
return KotlinCompilation().apply {
if (useKSP2) {
useKsp2()
} else {
languageVersion = "1.9"
}
inheritClassPath = true
configureKsp(useKSP2) {
symbolProcessorProviders += AutoServiceSymbolProcessor.Provider()
incremental = this@AutoServiceSymbolProcessorTest.incremental
}
}
}

Expand All @@ -71,13 +93,7 @@ class AutoServiceSymbolProcessorTest(private val incremental: Boolean) {
""",
)

val compilation =
KotlinCompilation().apply {
sources = listOf(source)
inheritClassPath = true
symbolProcessorProviders = listOf(AutoServiceSymbolProcessor.Provider())
kspIncremental = incremental
}
val compilation = newCompilation().apply { sources = listOf(source) }
val result = compilation.compile()
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
val generatedSourcesDir = compilation.kspSourcesDir
Expand All @@ -104,13 +120,7 @@ class AutoServiceSymbolProcessorTest(private val incremental: Boolean) {
""",
)

val compilation =
KotlinCompilation().apply {
sources = listOf(source)
inheritClassPath = true
symbolProcessorProviders = listOf(AutoServiceSymbolProcessor.Provider())
kspIncremental = incremental
}
val compilation = newCompilation().apply { sources = listOf(source) }
val result = compilation.compile()
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
val generatedSourcesDir = compilation.kspSourcesDir
Expand Down Expand Up @@ -138,13 +148,7 @@ class AutoServiceSymbolProcessorTest(private val incremental: Boolean) {
.trimIndent(),
)

val compilation =
KotlinCompilation().apply {
sources = listOf(source)
inheritClassPath = true
symbolProcessorProviders = listOf(AutoServiceSymbolProcessor.Provider())
kspIncremental = incremental
}
val compilation = newCompilation().apply { sources = listOf(source) }
val result = compilation.compile()
assertThat(result.exitCode).isEqualTo(ExitCode.COMPILATION_ERROR)
assertThat(result.messages)
Expand Down Expand Up @@ -217,7 +221,7 @@ class AutoServiceSymbolProcessorTest(private val incremental: Boolean) {
KotlinCompilation().apply {
sources = listOf(generateAnnotation, source)
inheritClassPath = true
symbolProcessorProviders =
symbolProcessorProviders +=
listOf(AutoServiceSymbolProcessor.Provider(), TacoGenerator.Provider())
kspIncremental = incremental
}
Expand Down

0 comments on commit 5b4b585

Please sign in to comment.