8000 Update Kotlin, KSP, KotlinPoet, and Gradle by eygraber · Pull Request #195 · evant/kotlin-inject · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update Kotlin, KSP, KotlinPoet, and Gradle #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .circleci/config.yml
10000
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1
orbs:
gradle: circleci/gradle@1.0.10
browser-tools: circleci/browser-tools@1.2.3
gradle: circleci/gradle@3.0.0
browser-tools: circleci/browser-tools@1.4.1
_defaults: &defaults
working_directory: ~/code
environment:
Expand Down Expand Up @@ -51,14 +51,10 @@ commands:
jobs:
build-linux:
docker:
- image: cimg/openjdk:11.0.11-browsers@sha256:02d8ac1beb99bff9c303376388355c6f87f9e29960804e920f01f30547214f7c
resource_class: medium+
- image: cimg/openjdk:17.0.7-browsers@sha256:52a950f68f31d7e947e9468e11acb38177272a59c446044d13f0c6d7d66d12ed
resource_class: large
<<: *defaults
steps:
# Work-around kotlin native using an old version of libtinfo https://github.com/circleci/circleci-images/issues/430
- run:
name: Install libtinfo5
command: sudo apt update && sudo apt install -y libtinfo5
- checkout
- browser-tools/install-chrome
- browser-tools/install-chromedriver
Expand Down
3 changes: 1 addition & 2 deletions ast/kapt/src/main/kotlin/me/tatarka/kotlin/ast/KaptUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import kotlinx.metadata.KmProperty
import kotlinx.metadata.KmType
import kotlinx.metadata.KmValueParameter
import kotlinx.metadata.jvm.JvmMethodSignature
import kotlinx.metadata.jvm.KotlinClassHeader
import kotlinx.metadata.jvm.KotlinClassMetadata
import me.tatarka.kotlin.ast.internal.HashCollector
import me.tatarka.kotlin.ast.internal.collectHash
Expand Down Expand Up @@ -46,7 +45,7 @@ internal fun Element.annotationAnnotatedWith(packageName: String, simpleName: St
internal val TypeElement.metadata: KotlinClassMetadata?
get() {
val meta = getAnnotation(Metadata::class.java) ?: return null
val header = KotlinClassHeader(
val header = Metadata(
kind = meta.kind,
data1 = meta.data1,
data2 = meta.data2,
Expand Down
8 changes: 8 additions & 0 deletions ast/kapt/src/main/kotlin/me/tatarka/kotlin/ast/ModelAst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,20 @@ private fun KmAnnotationArgument.asString(): String {
return when (this) {
is KmAnnotationArgument.LiteralValue<*> -> value.toString()
is KmAnnotationArgument.KClassValue -> className
is KmAnnotationArgument.ArrayKClassValue -> asString()
is KmAnnotationArgument.EnumValue -> "$enumClassName.$enumEntryName"
is KmAnnotationArgument.AnnotationValue -> annotation.asString()
is KmAnnotationArgument.ArrayValue -> "[${elements.joinToString { it.asString() }}]"
}
}

private fun KmAnnotationArgument.ArrayKClassValue.asString(): String =
buildString {
repeat(arrayDimensionCount) { append("Array<") }
append(className)
repeat(arrayDimensionCount) { append(">") }
}

private class ModelAstParam(
override val provider: ModelAstProvider,
override val element: VariableElement,
Expand Down
6 changes: 0 additions & 6 deletions ast/ksp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("kotlin-inject.jvm")
id("kotlin-inject.detekt")
Expand All @@ -11,7 +9,3 @@ dependencies {
api(libs.ksp)
implementation(libs.kotlinpoet.ksp)
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=com.squareup.kotlinpoet.ksp.KotlinPoetKspPreview"
}
17 changes: 10 additions & 7 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
buildscript {
dependencies {
with(libs.kotlin.gradle.get()) {
classpath("$group:$name:$embeddedKotlinVersion")
}
}
}
Comment on lines +1 to +7
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why this is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forcing Gradle to use Kotlin 1.9 results in errors, which I think has to do with https://kotlinlang.org/docs/whatsnew19.html#separate-compiler-plugins-for-official-kotlin-libraries but in any case Gradle has always said not to force a different version of Kotlin for their runtime because they offer no guarantees (Gradle 8.3 should have Kotlin 1.9 support).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah so this overrides the version of kotlin uses when compiling the build script logic right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.gradle.org/8.3-rc-1/release-notes.html

The rc releases sometimes have issues, but I've used them in the past with no problems. It should allow kapt to stay in if you really don't want to remove it yet.

If you do want to remove kapt, I have a stashed changeset that's most of the way there, and I can make a PR. Unless you want the cathartic experience of ripping it out 😅


plugins {
`kotlin-dsl`
}

dependencies {
implementation(libs.kotiln.gradle)
implementation(libs.kotlin.gradle)
implementation(libs.detekt.gradle)
// hack to access version catelouge https://github.com/gradle/gradle/issues/15383
// hack to access version catalogue https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}

java {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: to run with java 20 I had to add

java {
    targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType<KotlinCompile>().configureEach {
    compilerOptions.jvmTarget = JvmTarget.JVM_11
}

(17 probably would work as well)
but either way I think it's good to have for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a toolchain here would probably be a valid use case (and I tested that it works), but the alternative is to not use java 20 until Gradle supports it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the alternative is to not use java 20 until Gradle supports it

yeah true, I might end up adding a target here because it just means you'd be generating older class files than needed so it's not a huge issue, but it's not a priority or anything.

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
2 changes: 0 additions & 2 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
enableFeaturePreview("VERSION_CATALOGS")

dependencyResolutionManagement {
versionCatalogs {
val libs by creating {
Expand Down
12 changes: 12 additions & 0 deletions build-logic/src/main/kotlin/NativeTargets.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
val nativeTargets = arrayOf(
"linuxX64",
"macosX64", "macosArm64",
"iosArm64", "iosX64", "iosSimulatorArm64",
"tvosArm64", "tvosX64", "tvosSimulatorArm64",
"watchosArm32", "watchosArm64", "watchosX64", "watchosSimulatorArm64",
)

val nativeKspTestConfigurations = nativeTargets.map {
@Suppress("DEPRECATION")
"ksp${it.capitalize()}Test"
}
7 changes: 5 additions & 2 deletions build-logic/src/main/kotlin/kotlin-inject.jvm.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("jvm")
}

val libs = the<LibrariesForLibs>()

kotlin.compilerOptions.jvmTarget = JvmTarget.JVM_11

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

// Ensure xml test reports are generated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ val tests = tasks.withType<AbstractTestTask>()
val testsApple = tests.withType<KotlinNativeTest>().matching { it.targetName?.contains(Regex("macos|ios|tvos|watchos")) ?: false }

val testReport = rootProject.tasks.named("testReport", TestReport::class) {
reportOn(tests)
testResults.from(tests.map { it.binaryResultsDirectory })
}

val testReportApple = rootProject.tasks.named("testReportApple", TestReport::class) {
reportOn(testsApple)
testResults.from(testsApple.map { it.binaryResultsDirectory })
}

val copyTestResults = rootProject.tasks.named("copyTestResults", Copy::class) {
tests.forEach { test ->
dependsOn(test)
from(test.reports.junitXml.outputLocation.get().asFile) {
include("**/*.xml")
if (test is KotlinJvmTest) {
Expand All @@ -26,6 +27,7 @@ val copyTestResults = rootProject.tasks.named("copyTestResults", Copy::class) {

val copyTestResultsApple = rootProject.tasks.named("copyTestResultsApple", Copy::class) {
testsApple.forEach { test ->
dependsOn(test)
from(test.reports.junitXml.outputLocation.get().asFile) {
include("**/*.xml")
rename("(.*).xml", "$1[${test.targetName}].xml")
Expand Down
40 changes: 12 additions & 28 deletions build-logic/src/main/kotlin/kotlin-inject.multiplatform.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("multiplatform")
}

val nativeTargets = arrayOf(
"linuxX64",
"macosX64", "macosArm64",
"iosArm32", "iosArm64", "iosX64", "iosSimulatorArm64",
"tvosArm64", "tvosX64", "tvosSimulatorArm64",
"watchosArm32", "watchosArm64", "watchosX86", "watchosX64", "watchosSimulatorArm64",
)

kotlin {
js(BOTH) {
js {
browser()
nodejs()
}
Expand Down Expand Up @@ -49,6 +41,15 @@ kotlin {
}
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions.jvmTarget = JvmTarget.JVM_11
}

// Run only the native tests
val nativeTest by tasks.registering {
kotlin.targets.all {
Expand All @@ -58,23 +59,6 @@ val nativeTest by tasks.registering {
}
}

// Disable as ksp doesn't support js ir
tasks.withType<KotlinJsCompile>().configureEach {
if (name.contains("Test") && name.contains("Ir")) {
disableAndWarn()
}
}
tasks.withType<KotlinJsTest>().configureEach {
if (name.contains("Ir")) {
disableAndWarn()
}
}

fun Task.disableAndWarn() {
enabled = false
logger.warn("disabling: $name as ksp does not support js ir https://github.com/JetBrains/kotlin/pull/4264")
}

// Don't run npm install scripts, protects against
// https://blog.jetbrains.com/kotlin/2021/10/important-ua-parser-js-exploit-and-kotlin-js/ etc.
tasks.withType<KotlinNpmInstallTask> {
Expand Down
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ nexusPublishing {
}

val testReport by tasks.registering(TestReport::class) {
destinationDir = buildDir.resolve("reports")
destinationDirectory = buildDir.resolve("reports")
}

val copyTestResults by tasks.registering(Copy::class) {
destinationDir = buildDir.resolve("test-results")
includeEmptyDirs = false
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

val testReportApple by tasks.registering(TestReport::class) {
destinationDir = buildDir.resolve("reports")
destinationDirectory = buildDir.resolve("reports")
}

val copyTestResultsApple by tasks.registering(Copy::class) {
destinationDir = buildDir.resolve("test-results")
includeEmptyDirs = false
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

val check by tasks.getting
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
org.gradle.parallel=true
kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.ignoreDisabledTargets=true
kotlin.native.binary.memoryModel=experimental
org.gradle.jvmargs=-Xmx4G
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[versions]
kotlin-inject = "0.6.1"
kotlin = "1.5.31"
ksp = "1.5.31-1.0.1"
kotlinpoet = "1.10.1"
junit5 = "5.8.1"
kotlin = "1.9.0"
ksp = "1.9.0-1.0.11"
kotlinpoet = "1.14.2"
junit5 = "5.9.3"
detekt = "1.19.0"
[libraries]
kotiln-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
detekt-gradle = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
ksp = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
kotlin-compile-testing = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version = "1.4.5" }
room-compiler-processing-testing = { module = "androidx.room:room-compiler-processing-testing", version = "2.4.0-beta01" }
kotlin-compile-testing = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version = "1.5.0" }
room-compiler-processing-testing = { module = "androidx.room:room-compiler-processing-testing", version = "2.6.0-alpha02" }
kotlin-annotation-processing-embeddable = { module = "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable", version.ref = "kotlin" }
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.5.2" }
kotlinx-metadata-jvm = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", version = "0.3.0" }
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version = "0.16.3" }
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.7.2" }
kotlinx-metadata-jvm = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", version = "0.7.0" }
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version = "0.21.0" }
jdk-compiler = { module = "io.earcam.wrapped:jdk.compiler", version = "1.8.132" }
assertk = { module = "com.willowtreeapps.assertk:assertk", version = "0.25" }
burst-junit4 = { module = "com.squareup.burst:burst-junit4", version = "1.2.0" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
30 changes: 22 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +213,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
Loading
0