Skip to content

Commit

Permalink
Update to KSP 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 26, 2024
1 parent f94bb37 commit ea76c99
Show file tree
Hide file tree
Showing 48 changed files with 284 additions and 332 deletions.
11 changes: 8 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ allprojects {
}
}

dependencies {
// dokka(projects.ksp.annotations)
dokka(projects.ksp)
dokka(projects.kotlinpoet)
}

subprojects {
configureJVMTarget()
}

tasks {
dokkaHtmlMultiModule {
outputDirectory = layout.projectDirectory.dir("docs/api")
dokkaGeneratePublicationHtml {

}
}

6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/JVMTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
fun Project.configureJVMTarget() {
plugins.withId("org.gradle.java") {
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_21
}
}

plugins.withId("org.jetbrains.kotlin.jvm") {
the<KotlinJvmProjectExtension>().compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
jvmTarget = JvmTarget.JVM_21
}
}

Expand All @@ -26,7 +26,7 @@ fun Project.configureJVMTarget() {
compilations.all {
compileTaskProvider.configure {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
jvmTarget = JvmTarget.JVM_21
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/code-generator.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ kotlin {
}

named("generationSource") {
kotlin.srcDir(downloadSources.destinationDirectory.map { it.dir("commonMain") })
kotlin.srcDir(downloadSources.destinationDirectory.map { it.dir("jvmMain") })
}
}
}
Expand Down
63 changes: 32 additions & 31 deletions buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,42 @@ import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
plugins {
org.jetbrains.dokka
id("com.vanniktech.maven.publish.base")
org.jetbrains.kotlinx.`binary-compatibility-validator`
}
dokka {
dokkaSourceSets.configureEach {
suppressGeneratedFiles = false
jdkVersion = 8

val readme = layout.projectDirectory.file("README.md").asFile
if (readme.exists()) {
includes.from(readme)
}

tasks {
withType<AbstractDokkaLeafTask> {
dokkaSourceSets.configureEach {
suppressGeneratedFiles = false
jdkVersion = 8

val readme = layout.projectDirectory.file("README.md").asFile
if (readme.exists()) {
includes.from(readme)
externalDocumentationLinks {
create("square/kotlinpoet") {
url("https://square.github.io/kotlinpoet/1.x/kotlinpoet/")
packageListUrl("https://gist.githubusercontent.com/DRSchlaubi/8cf8ab7628b6926e1520fa046ced9c4a/raw/4252fe08441a40171d64cd633abac46729c33724/package-list")
}
}

externalDocumentationLink("https://square.github.io/kotlinpoet/1.x/kotlinpoet/kotlinpoet/")

sourceLink {
localDirectory = project.projectDir
remoteUrl = uri("https://github.com/kordlib/codegen/blob/main/${project.name}").toURL()
remoteLineSuffix = "#L"
}
sourceLink {
localDirectory = project.projectDir
remoteUrl = uri("https://github.com/kordlib/codegen/blob/main/${project.name}")
remoteLineSuffix = "#L"
}

perPackageOption {
// Ignore everything from square
@Language("RegExp")
matchingRegex = """com\.squareup\..*"""
suppress = true
}
perPackageOption {
// Ignore everything from square
@Language("RegExp")
matchingRegex = """com\.squareup\..*"""
suppress = true
}

perPackageOption {
// Ignore everything from square
@Language("RegExp")
matchingRegex = """dev.kord.codegen.ksp.processor.*"""
suppress = true
}
perPackageOption {
// Ignore everything from square
@Language("RegExp")
matchingRegex = """dev.kord.codegen.ksp.processor.*"""
suppress = true
}
}
}
Expand All @@ -53,10 +54,10 @@ mavenPublishing {
}

plugins.withId("org.jetbrains.kotlin.jvm") {
configure(KotlinJvm(JavadocJar.Dokka("dokkaHtml")))
configure(KotlinJvm(JavadocJar.Dokka("dokkaGeneratePublicationHtml")))
}

plugins.withId("org.jetbrains.kotlin.multiplatform") {
configure(KotlinMultiplatform(JavadocJar.Dokka("dokkaHtml")))
configure(KotlinMultiplatform(JavadocJar.Dokka("dokkaGeneratePublicationHtml")))
}
}
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
kotlin.code.style=official
#dokka will run out of memory with the default meta space
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m

# https://kotlinlang.org/docs/dokka-migration.html#set-the-opt-in-flag
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
2 changes: 2 additions & 0 deletions gradle/gradle-daemon-jvm.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#This file is generated by updateDaemonJvm
toolchainVersion=21
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlin = "2.0.0"
kotlinpoet = "1.18.1"
ksp = "2.0.0-1.0.24"
kotlin = "2.0.21"
kotlinpoet = "2.0.0"
ksp = "2.0.21-1.0.26"

# The compiled binary of codegen.kt we use to compile codegen.kt itself
codegen-kt = "main-SNAPSHOT"
Expand All @@ -19,10 +19,10 @@ mockk = { group = "io.mockk", name = "mockk", version = "1.13.12" }

kotlin-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
ksp-plugin = { group = "com.google.devtools.ksp", name = "symbol-processing-gradle-plugin", version.ref = "ksp" }
dokka-plugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version = "1.9.20" }
maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.28.0" }
dokka-plugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version = "2.0.0-Beta" }
maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.30.0" }

binary-compatibility-validator-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version = "0.15.0-Beta.2" }
binary-compatibility-validator-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version = "0.16.3" }

[bundles]
pluginsForBuildSrc = ["kotlin-plugin", "ksp-plugin", "dokka-plugin", "maven-publish-plugin", "binary-compatibility-validator-plugin"]
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
8 changes: 8 additions & 0 deletions kotlinpoet/api/kotlinpoet.api
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ public final class dev/kord/codegen/kotlinpoet/js/JsAnnotationsKt {
public static final fun experimentalJsReflectionCreateInstance (Lcom/squareup/kotlinpoet/PropertySpec$Builder;)V
public static final fun experimentalJsReflectionCreateInstance (Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder;)V
public static final fun experimentalJsReflectionCreateInstance (Lcom/squareup/kotlinpoet/TypeSpec$Builder;)V
public static final fun experimentalJsStatic (Lcom/squareup/kotlinpoet/FileSpec$Builder;)V
public static final fun experimentalJsStatic (Lcom/squareup/kotlinpoet/FunSpec$Builder;)V
public static final fun experimentalJsStatic (Lcom/squareup/kotlinpoet/ParameterSpec$Builder;)V
public static final fun experimentalJsStatic (Lcom/squareup/kotlinpoet/PropertySpec$Builder;)V
public static final fun experimentalJsStatic (Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder;)V
public static final fun experimentalJsStatic (Lcom/squareup/kotlinpoet/TypeSpec$Builder;)V
public static final fun ignore (Lcom/squareup/kotlinpoet/FunSpec$Builder;)V
public static final fun ignore (Lcom/squareup/kotlinpoet/PropertySpec$Builder;)V
public static final fun ignore (Lcom/squareup/kotlinpoet/TypeSpec$Builder;)V
Expand All @@ -327,5 +333,7 @@ public final class dev/kord/codegen/kotlinpoet/js/JsAnnotationsKt {
public static final fun jsName (Lcom/squareup/kotlinpoet/FunSpec$Builder;Ljava/lang/String;)V
public static final fun jsName (Lcom/squareup/kotlinpoet/PropertySpec$Builder;Ljava/lang/String;)V
public static final fun jsName (Lcom/squareup/kotlinpoet/TypeSpec$Builder;Ljava/lang/String;)V
public static final fun jsStatic (Lcom/squareup/kotlinpoet/FunSpec$Builder;)V
public static final fun jsStatic (Lcom/squareup/kotlinpoet/PropertySpec$Builder;)V
}

1 change: 1 addition & 0 deletions kotlinpoet/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

plugins {
`code-generator`
org.jetbrains.kotlinx.`binary-compatibility-validator`
`kord-publishing`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package dev.kord.codegen.kotlinpoet
import com.squareup.kotlinpoet.Annotatable
import com.squareup.kotlinpoet.asClassName

public inline fun <T : Annotatable.Builder<T>, reified A> Annotatable.Builder<T>.addAnnotation(): T
= addAnnotation(A::class.asClassName())
public inline fun <T : Annotatable.Builder<T>, reified A> Annotatable.Builder<T>.addAnnotation(): T = addAnnotation(A::class.asClassName())
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,29 @@ import kotlin.reflect.KClass

public typealias AnnotationSpecBuilderScope = @CodeGenDsl AnnotationSpec.Builder.() -> Unit

@DelicateKotlinPoetApi(message =
"Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
public fun AnnotationSpec(`annotation`: Annotation, includeDefaultValues: Boolean = false):
AnnotationSpec = `get`(`annotation`, includeDefaultValues)
@DelicateKotlinPoetApi(message = "Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
public fun AnnotationSpec(`annotation`: Annotation, includeDefaultValues: Boolean = false): AnnotationSpec = `get`(`annotation`, includeDefaultValues)

@DelicateKotlinPoetApi(message =
"Mirror APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@DelicateKotlinPoetApi(message = "Mirror APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
public fun AnnotationSpec(`annotation`: AnnotationMirror): AnnotationSpec = `get`(`annotation`)

public inline fun AnnotationSpec(type: ClassName, block: AnnotationSpecBuilderScope = {}):
AnnotationSpec {
public inline fun AnnotationSpec(type: ClassName, block: AnnotationSpecBuilderScope = {}): AnnotationSpec {
contract { callsInPlace(block, EXACTLY_ONCE) }
return AnnotationSpec.builder(type).apply(block).build()
}

public inline fun AnnotationSpec(type: ParameterizedTypeName, block: AnnotationSpecBuilderScope =
{}): AnnotationSpec {
public inline fun AnnotationSpec(type: ParameterizedTypeName, block: AnnotationSpecBuilderScope = {}): AnnotationSpec {
contract { callsInPlace(block, EXACTLY_ONCE) }
return AnnotationSpec.builder(type).apply(block).build()
}

@DelicateKotlinPoetApi(message =
"Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
public inline fun AnnotationSpec(type: Class<out Annotation>, block: AnnotationSpecBuilderScope =
{}): AnnotationSpec {
@DelicateKotlinPoetApi(message = "Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
public inline fun AnnotationSpec(type: Class<out Annotation>, block: AnnotationSpecBuilderScope = {}): AnnotationSpec {
contract { callsInPlace(block, EXACTLY_ONCE) }
return AnnotationSpec.builder(type).apply(block).build()
}

public inline fun AnnotationSpec(type: KClass<out Annotation>, block: AnnotationSpecBuilderScope =
{}): AnnotationSpec {
public inline fun AnnotationSpec(type: KClass<out Annotation>, block: AnnotationSpecBuilderScope = {}): AnnotationSpec {
contract { callsInPlace(block, EXACTLY_ONCE) }
return AnnotationSpec.builder(type).apply(block).build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import kotlin.contracts.contract

public typealias FileSpecBuilderScope = @CodeGenDsl FileSpec.Builder.() -> Unit

public fun FileSpec(packageName: String, typeSpec: TypeSpec): FileSpec = `get`(packageName,
typeSpec)
public fun FileSpec(packageName: String, typeSpec: TypeSpec): FileSpec = `get`(packageName, typeSpec)

public inline fun FileSpec(className: ClassName, block: FileSpecBuilderScope = {}): FileSpec {
contract { callsInPlace(block, EXACTLY_ONCE) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ import com.squareup.kotlinpoet.asClassName
import kotlin.String
import kotlin.collections.Iterable

public inline fun <reified C> FileSpec.Builder.addImport(vararg names: String): FileSpec.Builder =
addImport(C::class.asClassName(), names = names)
public inline fun <reified C> FileSpec.Builder.addImport(vararg names: String): FileSpec.Builder = addImport(C::class.asClassName(), names = names)

public inline fun <reified C> FileSpec.Builder.addImport(names: Iterable<String>): FileSpec.Builder
= addImport(C::class.asClassName(), names)
public inline fun <reified C> FileSpec.Builder.addImport(names: Iterable<String>): FileSpec.Builder = addImport(C::class.asClassName(), names)

public inline fun <reified C> FileSpec.Builder.addAliasedImport(`as`: String): FileSpec.Builder =
addAliasedImport(C::class.asClassName(), `as`)
public inline fun <reified C> FileSpec.Builder.addAliasedImport(`as`: String): FileSpec.Builder = addAliasedImport(C::class.asClassName(), `as`)

public inline fun <reified C> FileSpec.Builder.addAliasedImport(memberName: String, `as`: String):
FileSpec.Builder = addAliasedImport(C::class.asClassName(), memberName, `as`)
public inline fun <reified C> FileSpec.Builder.addAliasedImport(memberName: String, `as`: String): FileSpec.Builder = addAliasedImport(C::class.asClassName(), memberName, `as`)

public inline fun <reified A> FileSpec.Builder.addAnnotation(): FileSpec.Builder =
addAnnotation(A::class.asClassName())
public inline fun <reified A> FileSpec.Builder.addAnnotation(): FileSpec.Builder = addAnnotation(A::class.asClassName())
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.asClassName
import com.squareup.kotlinpoet.typeNameOf

public inline fun <reified R> FunSpec.Builder.`receiver`(kdoc: CodeBlock = emptyCodeBlock()):
FunSpec.Builder = `receiver`(typeNameOf<R>(), kdoc)
public inline fun <reified R> FunSpec.Builder.`receiver`(kdoc: CodeBlock = emptyCodeBlock()): FunSpec.Builder = `receiver`(typeNameOf<R>(), kdoc)

public inline fun <reified R> FunSpec.Builder.returns(kdoc: CodeBlock = emptyCodeBlock()):
FunSpec.Builder = returns(typeNameOf<R>(), kdoc)
public inline fun <reified R> FunSpec.Builder.returns(kdoc: CodeBlock = emptyCodeBlock()): FunSpec.Builder = returns(typeNameOf<R>(), kdoc)

public inline fun <reified A> FunSpec.Builder.addAnnotation(): FunSpec.Builder =
addAnnotation(A::class.asClassName())
public inline fun <reified A> FunSpec.Builder.addAnnotation(): FunSpec.Builder = addAnnotation(A::class.asClassName())
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@ import com.squareup.kotlinpoet.typeNameOf
import kotlin.collections.List

@ExperimentalKotlinPoetApi
public inline fun <reified R, reified R_>
LambdaTypeName.Companion.`get`(parameters: List<ParameterSpec> = emptyList(),
contextReceivers: List<TypeName> = emptyList()): LambdaTypeName = `get`(typeNameOf<R>(),
parameters, typeNameOf<R_>(), contextReceivers)
public inline fun <reified R, reified R_> LambdaTypeName.Companion.`get`(parameters: List<ParameterSpec> = emptyList(), contextReceivers: List<TypeName> = emptyList()): LambdaTypeName = `get`(typeNameOf<R>(), parameters, typeNameOf<R_>(), contextReceivers)

public inline fun <reified R, reified R_>
LambdaTypeName.Companion.`get`(parameters: List<ParameterSpec> = emptyList()): LambdaTypeName =
`get`(typeNameOf<R>(), parameters, typeNameOf<R_>())
public inline fun <reified R, reified R_> LambdaTypeName.Companion.`get`(parameters: List<ParameterSpec> = emptyList()): LambdaTypeName = `get`(typeNameOf<R>(), parameters, typeNameOf<R_>())

public inline fun <reified R, reified R_> LambdaTypeName.Companion.`get`(vararg parameters: TypeName
= emptyArray()): LambdaTypeName = `get`(typeNameOf<R>(), parameters = parameters,
typeNameOf<R_>())
public inline fun <reified R, reified R_> LambdaTypeName.Companion.`get`(vararg parameters: TypeName = emptyArray()): LambdaTypeName = `get`(typeNameOf<R>(), parameters = parameters, typeNameOf<R_>())

public inline fun <reified R, reified R_> LambdaTypeName.Companion.`get`(vararg
parameters: ParameterSpec = emptyArray()): LambdaTypeName = `get`(typeNameOf<R>(),
parameters = parameters, typeNameOf<R_>())
public inline fun <reified R, reified R_> LambdaTypeName.Companion.`get`(vararg parameters: ParameterSpec = emptyArray()): LambdaTypeName = `get`(typeNameOf<R>(), parameters = parameters, typeNameOf<R_>())
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import kotlin.reflect.KClass

public typealias ParameterSpecBuilderScope = @CodeGenDsl ParameterSpec.Builder.() -> Unit

@DelicateKotlinPoetApi(message =
"Element APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@DelicateKotlinPoetApi(message = "Element APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
public fun ParameterSpec(element: VariableElement): ParameterSpec = `get`(element)

public inline fun ParameterSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import com.squareup.kotlinpoet.asClassName
import com.squareup.kotlinpoet.typeNameOf
import kotlin.String

public inline fun <reified T> ParameterSpec.toBuilder(name: String = this.name):
ParameterSpec.Builder = toBuilder(name, typeNameOf<T>())
public inline fun <reified T> ParameterSpec.toBuilder(name: String = this.name): ParameterSpec.Builder = toBuilder(name, typeNameOf<T>())

public inline fun <reified A> ParameterSpec.Builder.addAnnotation(): ParameterSpec.Builder =
addAnnotation(A::class.asClassName())
public inline fun <reified A> ParameterSpec.Builder.addAnnotation(): ParameterSpec.Builder = addAnnotation(A::class.asClassName())

public inline fun <reified T> ParameterSpec.Companion.unnamed(): ParameterSpec =
unnamed(typeNameOf<T>())
public inline fun <reified T> ParameterSpec.Companion.unnamed(): ParameterSpec = unnamed(typeNameOf<T>())
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package dev.kord.codegen.kotlinpoet
import com.squareup.kotlinpoet.ParameterizedTypeName
import com.squareup.kotlinpoet.typeNameOf

public inline fun <reified T> ParameterizedTypeName.plusParameter(): ParameterizedTypeName =
plusParameter(typeNameOf<T>())
public inline fun <reified T> ParameterizedTypeName.plusParameter(): ParameterizedTypeName = plusParameter(typeNameOf<T>())
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public inline fun PropertySpec(
return PropertySpec.builder(name, type, modifiers).apply(block).build()
}

@DelicateKotlinPoetApi(message =
"Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@DelicateKotlinPoetApi(message = "Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
public inline fun PropertySpec(
name: String,
type: Type,
Expand Down
Loading

0 comments on commit ea76c99

Please sign in to comment.