Skip to content

Commit

Permalink
Update to Kotlin 1.9.0 (#428)
Browse files Browse the repository at this point in the history
* Update to kotlin 1.9.0-Beta

* CI

* Support k2 testing in MoshiIrVisitorTest

* Disable validation when k2 is enabled

* Add new kotlin IC flags

* Update metadata

* Update gradle/libs.versions.toml

* Disable proguard rule gen when K2's enabled

* Split CI jobs

* Clean up anonymous class checks

* Suppressions

* Force latest metadata for Kotlin binary compatibility check

* Update to RC

* Update CI + JDK 20

* Remove old java release

* Spotless

* Update deps and 1.9.0 stable

* Remove workaround

* KSP final

* Update ci
  • Loading branch information
ZacSweers authored Jul 6, 2023
1 parent f121744 commit 85efec3
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 30 deletions.
30 changes: 24 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ on: [ push, pull_request ]

jobs:
build:
name: 'JDK ${{ matrix.java }} - KSP ${{ matrix.ksp_enabled }} - Kotlin ${{ matrix.kotlin }}'
name: 'JDK ${{ matrix.java }} - KSP ${{ matrix.ksp_enabled }} - Kotlin ${{ matrix.kotlin }} - K2 ${{ matrix.k2_enabled }}'
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '19' ]
kotlin: [ '1.8.21' ]
java: [ '20' ]
kotlin: [ '1.9.0' ]
ksp_enabled: [ true, false ]
k2_enabled: [ true, false ]
fail-fast: false

env:
Expand All @@ -31,11 +32,28 @@ jobs:
java-version: ${{ matrix.java }}

- name: Build project
run: ./gradlew build check -Pmoshix.useKsp=${{ matrix.ksp_enabled }} --stacktrace
run: ./gradlew build check -Pmoshix.useKsp=${{ matrix.ksp_enabled }} -Pkotlin.experimental.tryK2=${{ matrix.k2_enabled }} --stacktrace

- name: Upload snapshot (main only)
publish-snapshot:
needs: 'build'
name: 'Publish snapshot (main only)'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1

- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '20'

- name: Publish
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
run: ./publish.sh --snapshot
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && matrix.java == '19' && !matrix.ksp_enabled
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && matrix.java == '20' && !matrix.ksp_enabled
22 changes: 17 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.vanniktech.maven.publish.MavenPublishBaseExtension
import java.net.URL
import java.net.URI
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
dependencies {
// Force latest metadata for Kotlin binary compatibility check
classpath(libs.kotlin.metadata)
}
}

plugins {
alias(libs.plugins.kotlinJvm) apply false
alias(libs.plugins.ksp) apply false
Expand Down Expand Up @@ -82,7 +88,9 @@ subprojects {
provider<String> { findProperty("moshix.javaReleaseVersion") as? String? }
.orElse(libs.versions.jvmTarget)
.map(String::toInt)
configure<JavaPluginExtension> { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) } }
configure<JavaPluginExtension> {
toolchain { languageVersion.set(JavaLanguageVersion.of(libs.versions.jdk.get().toInt())) }
}
project.tasks.withType<JavaCompile>().configureEach { options.release.set(jvmTargetProvider) }
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
Expand All @@ -107,8 +115,12 @@ subprojects {
outputDirectory.set(rootProject.rootDir.resolve("docs/0.x"))
dokkaSourceSets.configureEach {
skipDeprecated.set(true)
externalDocumentationLink { url.set(URL("https://square.github.io/okio/2.x/okio/")) }
externalDocumentationLink { url.set(URL("https://square.github.io/moshi/1.x/moshi/")) }
externalDocumentationLink {
url.set(URI("https://square.github.io/okio/2.x/okio/").toURL())
}
externalDocumentationLink {
url.set(URI("https://square.github.io/moshi/1.x/moshi/").toURL())
}
}
}
configure<MavenPublishBaseExtension> { publishToMavenCentral(automaticRelease = true) }
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ org.gradle.configureondemand=false
kapt.include.compile.classpath=false

ksp.version.check=false

# New Kotlin IC flags
kotlin.compiler.suppressExperimentalICOptimizationsWarning=true
kotlin.compiler.keepIncrementalCompilationCachesInMemory=true
kotlin.compiler.preciseCompilationResultsBackup=true
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ agp = "8.0.2"
autoService = "1.1.1"
gjf = "1.13.0"
incap = "1.0.0"
javaRelease = "8"
jdk = "20"
jvmTarget = "11"
kotlin = "1.8.21"
kotlin = "1.9.0"
kotlinCompileTesting = "0.2.1"
kotlinpoet = "1.12.0"
ksp = "1.8.22-1.0.11"
ksp = "1.9.0-1.0.11"
ktfmt = "0.44"
moshi = "1.15.0"
okhttp = "4.11.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ internal class ProguardRuleGenerationExtension(
project.extensionArea.registerExtensionPoint(
PsiTreeChangeListener.EP.name,
PsiTreeChangeAdapter::class.java.canonicalName,
ExtensionPoint.Kind.INTERFACE
ExtensionPoint.Kind.INTERFACE,
false
)
generator = ProguardRuleGenerator(resourcesDir)
initialized = true
Expand All @@ -91,7 +92,7 @@ internal class ProguardRuleGenerationExtension(
val isMoshiSealed = (enableSealed && generatorKey.startsWith("sealed:"))
if (generatorKey.isEmpty() || isMoshiSealed) {
val targetType = psiClass.asClassName()
val hasGenerics = !psiClass.typeParameters.isNullOrEmpty()
val hasGenerics = psiClass.typeParameters.isNotEmpty()
val adapterName = "${targetType.simpleNames.joinToString(separator = "_")}JsonAdapter"
val adapterConstructorParams =
when (hasGenerics) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,8 @@ class MoshiIrVisitorTest(private val useK2: Boolean) {
verbose = false
jvmTarget = JvmTarget.fromString(System.getProperty("moshix.jvmTarget"))!!.description
supportsK2 = true
// Necessary for K2 testing, even if useK2 itself isn't part of this test!
kotlincArguments += listOf("-Xskip-prerelease-check", "-Xallow-unstable-dependencies")
if (this@MoshiIrVisitorTest.useK2) {
languageVersion = "2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion moshi-ir/moshi-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ plugins {
alias(libs.plugins.spotless)
}

java { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) } }
java { toolchain { languageVersion.set(JavaLanguageVersion.of(libs.versions.jdk.get().toInt())) } }

tasks.withType<JavaCompile>().configureEach {
options.release.set(libs.versions.jvmTarget.map(String::toInt))
Expand Down
7 changes: 6 additions & 1 deletion moshi-ir/moshi-kotlin-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ plugins {
alias(libs.plugins.moshix)
}

moshi { enableSealed.set(true) }
moshi {
enableSealed.set(true)
if (findProperty("kotlin.experimental.tryK2") == "true") {
generateProguardRules.set(false)
}
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions { freeCompilerArgs.addAll("-opt-in=kotlin.ExperimentalStdlibApi") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ public class MetadataKotlinJsonAdapterFactory : JsonAdapter.Factory {
// Fall back to a reflective adapter when the generated adapter is not found.
}

require(!rawType.isLocalClass) {
"Cannot serialize local class or object expression ${rawType.name}"
}
require(!rawType.isLocalClass) { "Cannot serialize local class ${rawType.name}" }

require(!rawType.isAnonymousClass) { "Cannot serialize anonymous class ${rawType.name}" }

val kmClass = rawType.header()?.toKmClass() ?: return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class KotlinJsonAdapterTest {
assertThat(decoded.b).isEqualTo(5)
}

@Suppress("CanBePrimaryConstructorProperty")
class ImmutableProperties(a: Int, b: Int) {
val a = a
val b = b
Expand Down Expand Up @@ -741,7 +742,7 @@ class KotlinJsonAdapterTest {
assertThat(e)
.hasMessageThat()
.contains(
"Cannot serialize local class or object expression " +
"Cannot serialize local class " +
"dev.zacsweers.moshix.reflect.KotlinJsonAdapterTest\$localClassesNotSupported\$LocalClass"
)
}
Expand Down Expand Up @@ -779,17 +780,10 @@ class KotlinJsonAdapterTest {
fail()
} catch (e: IllegalArgumentException) {
// anonymous/local classes are slightly different in bytecode across JVM versions
val javaVersion = System.getProperty("java.version")
val type =
if (javaVersion.startsWith("1.8")) {
"local class or object expression"
} else {
"anonymous class"
}
assertThat(e)
.hasMessageThat()
.contains(
"Cannot serialize $type " +
"Cannot serialize anonymous class " +
"dev.zacsweers.moshix.reflect.KotlinJsonAdapterTest\$anonymousClassesNotSupported" +
"\$expression$1"
)
Expand Down Expand Up @@ -1317,6 +1311,7 @@ class KotlinJsonAdapterTest {
val moshi = Moshi.Builder().add(MetadataKotlinJsonAdapterFactory()).build()
val adapter = moshi.adapter(type)

@Suppress("DEPRECATION")
Assertions.assertThat(adapter.fromJson(json)).isEqualToComparingFieldByFieldRecursively(value)
assertThat(adapter.toJson(value)).isEqualTo(json)
}
Expand Down

0 comments on commit 85efec3

Please sign in to comment.