Skip to content

Commit

Permalink
Update to Kotlin 1.9.0 (#61)
Browse files Browse the repository at this point in the history
* Prep for Kotlin 1.9.0

* Link issue

* arg cleanup

* Disable validation with k2

* Remove unnecessary androidx annotation

* Update to RC + JDK 20

* 1.9.0 final

* Update deps and coroutines

* KSP final
  • Loading branch information
ZacSweers authored Jul 6, 2023
1 parent de9b2e0 commit 925da70
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ jobs:
key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('checksum.txt') }}
restore-keys: |
${{ runner.os }}-gradle-${{ matrix.java-version }}-
- name: Configure JDK
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '17'
java-version: '20'

- name: Test
run: ./gradlew build check
Expand Down
64 changes: 39 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.google.devtools.ksp.gradle.KspTaskJvm
import io.gitlab.arturbosch.detekt.Detekt
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.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions

plugins {
kotlin("jvm") version libs.versions.kotlin.get()
alias(libs.plugins.kotlin.jvm)
`java-test-fixtures`
alias(libs.plugins.dokka)
alias(libs.plugins.ksp)
Expand All @@ -30,43 +31,57 @@ plugins {
alias(libs.plugins.binaryCompatibilityValidator)
}

repositories {
mavenCentral()
google() // for androidx.annotation
}
repositories { mavenCentral() }

val tomlJvmTarget = libs.versions.jvmTarget.get()

pluginManager.withPlugin("java") {
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(11) }
project.tasks.withType<JavaCompile>().configureEach { options.release.set(tomlJvmTarget.toInt()) }
}

val tomlJvmTarget = libs.versions.jvmTarget.get()
apiValidation {
// https://github.com/Kotlin/binary-compatibility-validator/issues/139
validationDisabled = findProperty("kotlin.experimental.tryK2") == "true"
}

val kotlinCompilerOptions: KotlinJvmCompilerOptions.() -> Unit = {
progressiveMode.set(true)
jvmTarget.set(libs.versions.jvmTarget.map(JvmTarget::fromTarget))
}

tasks.withType<KotlinCompile>().configureEach {
val taskName = name
kotlin {
explicitApi()
compilerOptions(kotlinCompilerOptions)
}

tasks.compileTestKotlin {
compilerOptions {
jvmTarget.set(libs.versions.jvmTarget.map(JvmTarget::fromTarget))
if (taskName == "compileTestKotlin") {
freeCompilerArgs.add("-opt-in=kotlin.ExperimentalStdlibApi")
freeCompilerArgs.add("-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi")
// Enable new jvmdefault behavior
// https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-m3-generating-default-methods-in-interfaces/
freeCompilerArgs.add("-Xjvm-default=all")
}
freeCompilerArgs.addAll("-progressive", "-opt-in=kotlin.RequiresOptIn")
optIn.addAll(
"kotlin.ExperimentalStdlibApi",
"kotlinx.coroutines.ExperimentalCoroutinesApi",
)
// Enable new jvmdefault behavior
// https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-m3-generating-default-methods-in-interfaces/
freeCompilerArgs.add("-Xjvm-default=all")
}
}

tasks.withType<Detekt>().configureEach { jvmTarget = tomlJvmTarget }
// https://github.com/google/ksp/issues/1387
tasks.withType<KspTaskJvm>().configureEach { compilerOptions(kotlinCompilerOptions) }

kotlin { explicitApi() }
tasks.withType<Detekt>().configureEach { jvmTarget = tomlJvmTarget }

tasks.named<DokkaTask>("dokkaHtml") {
outputDirectory.set(rootDir.resolve("docs/0.x"))
dokkaSourceSets.configureEach {
skipDeprecated.set(true)
externalDocumentationLink { url.set(URL("https://square.github.io/retrofit/2.x/retrofit/")) }
externalDocumentationLink {
url.set(URI("https://square.github.io/retrofit/2.x/retrofit/").toURL())
}
}
}

Expand Down Expand Up @@ -125,7 +140,6 @@ dependencies {
kspTest(libs.autoService.ksp)

// Android APIs access, gated at runtime
testFixturesCompileOnly(libs.androidx.annotation)
testFixturesCompileOnly(libs.androidProcessingApi)
testFixturesImplementation(libs.coroutines.core)
// For access to Types
Expand Down
21 changes: 8 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# suppress inspection "AlphaUnsortedPropertiesFile" for whole file
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

# Disabled as this has no benefits in studio builds and only marginal benefits in command line, but
# can cause problems with Kotlin Gradle DSL. We're observing this for a week to see if/how it affects
# metrics.
org.gradle.configureondemand=false

# Enable compilation avoidance (by turning off discovery of annotation processors on the compile classpath).
# https://kotlinlang.org/docs/reference/kapt.html#compile-avoidance-for-kapt-since-1320
kapt.include.compile.classpath=false
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true

# Add opens for Kapt
# https://youtrack.jetbrains.com/issue/KT-45545#focus=Comments-27-4862682.0-0
# Adds exports for GJF in spotless
# https://github.com/diffplug/spotless/issues/834
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# New Kotlin IC flags
kotlin.compiler.suppressExperimentalICOptimizationsWarning=true
kotlin.compiler.keepIncrementalCompilationCachesInMemory=true
kotlin.compiler.preciseCompilationResultsBackup=true

POM_NAME=EitherNet
POM_ARTIFACT_ID=eithernet
Expand Down
23 changes: 12 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
[versions]
coroutines = "1.7.1"
kotlin = "1.8.21"
coroutines = "1.7.2"
kotlin = "1.9.0"
jdk = "20"
jvmTarget = "11"
ksp = "1.8.21-1.0.11"
ktfmt = "0.43"
ksp = "1.9.0-1.0.11"
ktfmt = "0.44"
moshi = "1.15.0"
okhttp = "4.9.0"
retrofit = "2.9.0"

[plugins]
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.1" }
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.21.0" }
dokka = { id = "org.jetbrains.dokka", version = "1.8.10" }
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" }
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.0" }
dokka = { id = "org.jetbrains.dokka", version = "1.8.20" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.2" }
spotless = { id = "com.diffplug.spotless", version = "6.18.0" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.3" }
spotless = { id = "com.diffplug.spotless", version = "6.19.0" }

[libraries]
androidProcessingApi = "com.google.android:android:4.1.1.4"
androidx-annotation = "androidx.annotation:annotation:1.2.0"
autoService-annotations = "com.google.auto.service:auto-service-annotations:1.0"
autoService-ksp = "dev.zacsweers.autoservice:auto-service-ksp:1.0.0"
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
Expand All @@ -33,4 +34,4 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okhttp-mockwebserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "okhttp" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-converterScalars = { module = "com.squareup.retrofit2:converter-scalars", version.ref = "retrofit" }
truth = "com.google.truth:truth:1.1.3"
truth = "com.google.truth:truth:1.1.4"
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ 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.
Expand Down
2 changes: 0 additions & 2 deletions src/testFixtures/java/com/slack/eithernet/test/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package com.slack.eithernet.test

import android.annotation.SuppressLint
import android.os.Build.VERSION
import androidx.annotation.RequiresApi
import java.lang.invoke.MethodHandles
import java.lang.invoke.MethodHandles.Lookup
import java.lang.reflect.Constructor
Expand All @@ -32,7 +31,6 @@ internal open class Platform(private val hasJava8Types: Boolean) {

init {
var lookupConstructor: Constructor<Lookup>? = null
@RequiresApi(26)
if (hasJava8Types) {
try {
// Because the service interface might not be public, we need to use a MethodHandle lookup
Expand Down

0 comments on commit 925da70

Please sign in to comment.