Skip to content

Commit

Permalink
Kotlin 1.8
Browse files Browse the repository at this point in the history
Upgrade Anvil to Kotlin 1.8 and stop supporting 1.7 moving forward.
  • Loading branch information
vRallev committed Jan 9, 2023
1 parent 3fdaf27 commit 5bb964b
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 396 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs :
fail-fast : false
matrix :
# We do not run this job with Kotlin 1.8 because the old backend is removed in 1.8
kotlin-version : [ 1.7.20]
kotlin-version : [ 1.8.0 ]

steps :
- uses : actions/checkout@v2
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs :
strategy :
fail-fast : false
matrix :
kotlin-version : [ 1.7.20, 1.8.0 ]
kotlin-version : [ 1.8.0 ]

steps :
- uses : actions/checkout@v2
Expand Down Expand Up @@ -168,15 +168,8 @@ jobs :
java-version : '11'
check-latest : true

# TODO: Revert release changes when we drop support for 1.7
- name : Publish Snapshots 1.7
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -Psquare.kotlinVersion=1.7.20 && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace -Psquare.kotlinVersion=1.7.20 && cd ..
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}

- name : Publish Snapshots 1.8
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -Psquare.kotlinVersion=1.8.0 -PVERSION_NAME=2.4.4-1-8-0-SNAPSHOT && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace -Psquare.kotlinVersion=1.8.0 -PVERSION_NAME=2.4.4-1-8-0-SNAPSHOT && cd ..
- name : Publish Snapshots
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -PVERSION_NAME=2.4.4 && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace -PVERSION_NAME=2.4.4 && cd ..
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
Expand All @@ -195,7 +188,7 @@ jobs :
# solution.
fail-fast : false
matrix :
kotlin-version : [ 1.7.20, 1.8.0 ]
kotlin-version : [ 1.8.0 ]
agp-version : [ 4.2.2, 7.0.4, 7.1.1, 7.2.0-beta01, 7.3.0-alpha01 ]

steps :
Expand Down Expand Up @@ -246,7 +239,7 @@ jobs :
# solution.
fail-fast : false
matrix :
kotlin-version : [ 1.7.20, 1.8.0 ]
kotlin-version : [ 1.8.0 ]

steps :
- uses : actions/checkout@v2
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@ jobs :
java-version : '11'
check-latest : true

# TODO: Revert release changes when we drop support for 1.7
- name : Publish Release 1.7
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -Psquare.kotlinVersion=1.7.20 && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace -Psquare.kotlinVersion=1.7.20 && cd ..
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey : ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword : ''

- name : Publish Release 1.8
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -Psquare.kotlinVersion=1.8.0 -PVERSION_NAME=2.4.4-1-8-0 && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace -Psquare.kotlinVersion=1.8.0 -PVERSION_NAME=2.4.4-1-8-0 && cd ..
- name : Publish Release
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace && cd ..
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Removed

- Remove support for Kotlin 1.7. Anvil only supports Kotlin 1.8 moving forward.

### Fixed

### Security
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ subprojects {
}

//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask).configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
if (parent?.path != ':integration-tests:mpp') {
// The configuration for KMP projects is different. We should fix that eventually.
//
// Caused by: groovy.lang.MissingPropertyException: Could not set unknown property 'jvmTarget' for object of type org.jetbrains.kotlin.gradle.tasks.internal.KotlinMultiplatformCommonOptionsCompat.
jvmTarget = JavaVersion.VERSION_1_8
}

allWarningsAsErrors = rootProject.ext.makeWarningsErrors
freeCompilerArgs += ["-opt-in=kotlin.RequiresOptIn"]
Expand Down
20 changes: 6 additions & 14 deletions compiler-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
implementation deps.dagger2.dagger
implementation deps.inject

testFixturesApi kotlinCompileTesting
testFixturesApi deps.kotlin.compile_testing
testFixturesImplementation project(':compiler')
testFixturesImplementation deps.dagger2.compiler
testFixturesImplementation deps.dagger2.dagger
Expand All @@ -33,24 +33,16 @@ dependencies {
compileOnly project(':compiler')
compileOnly deps.dagger2.compiler
compileOnly deps.junit
compileOnly kotlinCompileTesting
compileOnly deps.kotlin.compile_testing
compileOnly deps.truth
}
}

// We conditionally include one of two source sets here because there are some breaking API changes
// between Kotlin 1.7 and 1.8. We must support both until 1.8 is fully released and we drop 1.7.
if (rootProject.ext.kotlinPreview) {
sourceSets.testFixtures.java.srcDirs += ['src/testFixtures/preview']

//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions {
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask).configureEach {
compilerOptions {
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
} else {
sourceSets.testFixtures.java.srcDirs += ['src/testFixtures/stable']
}

private def getSystemProperty(String name, String defaultValue = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ public class AnvilCompilation internal constructor(
if (!enableAnvil) return@apply

kotlinCompilation.apply {
setRegistrars(
listOf(
AnvilComponentRegistrar().also { it.addCodeGenerators(codeGenerators) }
)
componentRegistrars = listOf(
AnvilComponentRegistrar().also { it.addCodeGenerators(codeGenerators) }
)
if (enableDaggerAnnotationProcessor) {
annotationProcessors = listOf(ComponentProcessor(), AutoAnnotationProcessor())
Expand Down Expand Up @@ -99,7 +97,6 @@ public class AnvilCompilation internal constructor(
public fun useIR(useIR: Boolean) = apply {
checkNotCompiled()
kotlinCompilation.useIR = useIR
kotlinCompilation.useOldBackend = !useIR

if (!useIR) {
// To suppress:
Expand Down

This file was deleted.

This file was deleted.

27 changes: 8 additions & 19 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,19 @@ dependencies {
testImplementation testFixtures(project(":compiler-utils"))
testImplementation deps.dagger2.compiler
testImplementation deps.kotlin.annotation_processing_embeddable
testImplementation kotlinCompileTesting
testImplementation deps.kotlin.compile_testing
testImplementation deps.kotlin.compiler
testImplementation deps.kotlin.test
testImplementation deps.truth
}

if (rootProject.ext.kotlinPreview) {
//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions {
// The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin
// compiler requires this flag when doing so.
freeCompilerArgs.add("-Xjvm-default=all")
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
}
} else {
//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
// The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin
// compiler requires this flag when doing so.
freeCompilerArgs.add("-Xjvm-default=all")
}
//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask).configureEach {
compilerOptions {
// The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin
// compiler requires this flag when doing so.
freeCompilerArgs.add("-Xjvm-default=all")
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ class InterfaceMergerTest(
) {
assertThat(exitCode).isError()
// Position to the class.
if (KOTLIN_PREVIEW) {
assertThat(messages).contains("Source0.kt:6:16")
} else {
assertThat(messages).contains("Source0.kt: (6, 16)")
}
assertThat(messages).contains("Source0.kt:6:16")
}
}

Expand Down Expand Up @@ -207,11 +203,7 @@ class InterfaceMergerTest(
assertThat(exitCode).isError()
// Position to the class. Unfortunately, a different error is reported that the class is
// missing an @Module annotation.
if (KOTLIN_PREVIEW) {
assertThat(messages).contains("Source0.kt:7:7")
} else {
assertThat(messages).contains("Source0.kt: (7, 7)")
}
assertThat(messages).contains("Source0.kt:7:7")
}
}

Expand Down Expand Up @@ -240,11 +232,7 @@ class InterfaceMergerTest(
assertThat(exitCode).isError()
// Position to the class. Unfortunately, a different error is reported that the class is
// missing an @Module annotation.
if (KOTLIN_PREVIEW) {
assertThat(messages).contains("Source0.kt:14:11")
} else {
assertThat(messages).contains("Source0.kt: (14, 11)")
}
assertThat(messages).contains("Source0.kt:14:11")
assertThat(messages).contains(
"com.squareup.test.SecondContributingInterface with scopes [kotlin.Any] wants to replace " +
"com.squareup.test.ContributingInterface, but the replaced class isn't contributed " +
Expand Down Expand Up @@ -332,11 +320,7 @@ class InterfaceMergerTest(
) {
assertThat(exitCode).isError()
// Position to the class.
if (KOTLIN_PREVIEW) {
assertThat(messages).contains("Source0.kt:18:11")
} else {
assertThat(messages).contains("Source0.kt: (18, 11)")
}
assertThat(messages).contains("Source0.kt:18:11")
assertThat(messages).contains(
"com.squareup.test.ComponentInterface with scopes [kotlin.Any] wants to exclude " +
"com.squareup.test.ContributingInterface, but the excluded class isn't contributed " +
Expand Down Expand Up @@ -467,11 +451,7 @@ class InterfaceMergerTest(
) {
assertThat(exitCode).isError()
// Position to the class.
if (KOTLIN_PREVIEW) {
assertThat(messages).contains("Source0.kt:7")
} else {
assertThat(messages).contains("Source0.kt: (7, ")
}
assertThat(messages).contains("Source0.kt:7")
}
}
}
Expand Down
Loading

0 comments on commit 5bb964b

Please sign in to comment.