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 plugin compatibility with Kotlin Gradle Plugin 1.9.0 release (#715) (v0.9.x backport) #721

Merged
merged 1 commit into from
Jul 13, 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
19 changes: 14 additions & 5 deletions src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import org.gradle.api.provider.Provider
import org.gradle.api.tasks.SourceSet
import org.gradle.language.jvm.tasks.ProcessResources
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/**
Expand Down Expand Up @@ -347,11 +348,19 @@ class ProtobufPlugin implements Plugin<Project> {
variant.registerJavaGeneratingTask(generateProtoTask.get(), generateProtoTask.get().outputSourceDirectories)

project.plugins.withId("org.jetbrains.kotlin.android") {
project.afterEvaluate {
String compileKotlinTaskName = Utils.getKotlinAndroidCompileTaskName(project, variant.name)
project.tasks.named(compileKotlinTaskName, KotlinCompile) { KotlinCompile task ->
task.dependsOn(generateProtoTask)
task.source(generateProtoTask.get().outputSourceDirectories)
// Checking if Kotlin plugin is a recent one - 1.7.20+
if (it.respondsTo("getPluginVersion")) {
KotlinAndroidProjectExtension kotlinExtension = project.extensions.getByType(KotlinAndroidProjectExtension)
kotlinExtension.target.compilations.named(variant.name) {
it.defaultSourceSet.kotlin.srcDirs(variantSourceSet.output)
}
} else {
project.afterEvaluate {
String compileKotlinTaskName = Utils.getKotlinAndroidCompileTaskName(project, variant.name)
project.tasks.named(compileKotlinTaskName, KotlinCompile) { KotlinCompile task ->
task.dependsOn(generateProtoTask)
task.source(generateProtoTask.get().outputSourceDirectories)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import spock.lang.Unroll

@CompileDynamic
class ProtobufAndroidPluginKotlinTest extends Specification {
private static final List<String> GRADLE_VERSION = ["5.6", "6.5.1", "7.4.2", "7.6"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "7.2.1", "7.3.1"]
private static final List<String> KOTLIN_VERSION = ["1.3.20", "1.3.20", "1.3.40", "1.7.20"]
private static final List<String> GRADLE_VERSION = ["5.6", "6.5.1", "7.4.2", "7.6.2", "7.6.2"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "7.2.1", "7.3.1", "7.4.2"]
private static final List<String> KOTLIN_VERSION = ["1.3.20", "1.3.20", "1.3.40", "1.7.20", "1.9.0"]

/**
* This test may take a significant amount of Gradle daemon Metaspace memory in some
Expand Down
Loading