Skip to content
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

Fix Kotlin 1.7 compatibility #4187

Merged
merged 2 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -65,7 +65,7 @@ object AndroidTaskConfigurator {
// Tell the kotlin compiler to compile our files
project.tasks.named("compile${variant.name.capitalize()}Kotlin").configure {
it.dependsOn(codegenProvider)
(it as KotlinCompile).source(codegenProvider.get().outputDir.asFile.get())
(it as KotlinCompile).invokeSource(codegenProvider.get().outputDir.asFile.get())
}
} else {
variant.registerJavaGeneratingTask(codegenProvider.get(), codegenProvider.get().outputDir.get().asFile)
Expand All @@ -79,9 +79,9 @@ object AndroidTaskConfigurator {
*/
project.tasks.matching {
it.name == "compile${variant.name.capitalize()}Kotlin"
}.configureEach{
}.configureEach {
it.dependsOn(codegenProvider)
(it as KotlinCompile).source(codegenProvider.get().outputDir.get().asFile)
(it as KotlinCompile).invokeSource(codegenProvider.get().outputDir.get().asFile)
}
}
}
Expand Down
Expand Up @@ -61,7 +61,7 @@ object JvmTaskConfigurator {
project.tasks.matching {
it.name == "compileKotlin"
}.configureEach {
(it as KotlinCompile).source(codegenProvider.get().outputDir.get().asFile)
(it as KotlinCompile).invokeSource(codegenProvider.get().outputDir.get().asFile)
}
}
sourceDirectorySet.srcDir(codegenProvider.flatMap { it.outputDir })
Expand Down
@@ -0,0 +1,14 @@
package com.apollographql.apollo.gradle.internal

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// The signature of this function changed in Kotlin 1.7, so we invoke it reflectively
// to support both.
// 1.6.x: `fun source(vararg sources: Any): SourceTask
// 1.7.x: `fun source(vararg sources: Any)
BoD marked this conversation as resolved.
Show resolved Hide resolved
fun KotlinCompile.invokeSource(source: Any) {
SOURCE_FUNCTION.invoke(this, arrayOf(source))
}

private val SOURCE_FUNCTION = KotlinCompile::class.java
.getMethod("source", java.lang.reflect.Array.newInstance(Any::class.java, 0).javaClass)