From 4cf2e621b307256617437c97bc416b7b9cd1dc5d Mon Sep 17 00:00:00 2001 From: Andrey Stepankov Date: Tue, 10 Jan 2023 22:22:23 +0300 Subject: [PATCH] Use KotlinCompile type directly (#657) * Use KotlinCompile type directly * Add Kotlin 1.7.20, Gradle 7.6 versions to tests * Fix codenarc issues * Do not run all gradleVersion * kotlinVersion combinations * Bump kotlin and agp versions --- build.gradle | 1 + .../com/google/protobuf/gradle/ProtobufPlugin.groovy | 4 ++-- .../gradle/ProtobufAndroidPluginKotlinTest.groovy | 6 +++--- .../protobuf/gradle/ProtobufJavaPluginTest.groovy | 10 ++++++---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index fb6e6b92..545e487d 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,7 @@ configurations { dependencies { compileOnly "com.android.tools.build:gradle:4.1.0" + compileOnly "org.jetbrains.kotlin.android:org.jetbrains.kotlin.android.gradle.plugin:1.7.22" implementation 'com.google.gradle:osdetector-gradle-plugin:1.7.1' diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 9853f0ee..c0c2bae5 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -55,9 +55,9 @@ import org.gradle.api.internal.artifacts.ArtifactAttributes import org.gradle.api.plugins.AppliedPlugin import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.SourceTask import org.gradle.language.jvm.tasks.ProcessResources import org.gradle.util.GradleVersion +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile /** * The main class for the protobuf plugin. @@ -349,7 +349,7 @@ class ProtobufPlugin implements Plugin { project.plugins.withId("org.jetbrains.kotlin.android") { project.afterEvaluate { String compileKotlinTaskName = Utils.getKotlinAndroidCompileTaskName(project, variant.name) - project.tasks.named(compileKotlinTaskName, SourceTask) { SourceTask task -> + project.tasks.named(compileKotlinTaskName, KotlinCompile) { KotlinCompile task -> task.dependsOn(generateProtoTask) task.source(generateProtoTask.get().outputSourceDirectories) } diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy index 55075117..ea767e30 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy @@ -8,9 +8,9 @@ import spock.lang.Unroll @CompileDynamic class ProtobufAndroidPluginKotlinTest extends Specification { - private static final List GRADLE_VERSION = ["5.6", "6.5.1", "7.4.2"] - private static final List ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "7.2.1"] - private static final List KOTLIN_VERSION = ["1.3.20", "1.3.20", "1.3.40"] + private static final List GRADLE_VERSION = ["5.6", "6.5.1", "7.4.2", "7.6"] + private static final List ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "7.2.1", "7.3.1"] + private static final List KOTLIN_VERSION = ["1.3.20", "1.3.20", "1.3.40", "1.7.20"] /** * This test may take a significant amount of Gradle daemon Metaspace memory in some diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy index 8798574e..d3c3be1d 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy @@ -15,8 +15,8 @@ import spock.lang.Unroll @CompileDynamic class ProtobufJavaPluginTest extends Specification { // Current supported version is Gradle 5+. - private static final List GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1", "7.4.2"] - private static final List KOTLIN_VERSIONS = ["1.3.20", "1.3.31", "1.3.40"] + private static final List GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1", "7.4.2", "7.6"] + private static final List KOTLIN_VERSIONS = ["1.3.72", "1.4.32", "1.5.32", "1.6.21", "1.7.21"] void "testApplying java and com.google.protobuf adds corresponding task to project"() { given: "a basic project with java and com.google.protobuf" @@ -196,7 +196,8 @@ class ProtobufJavaPluginTest extends Specification { ProtobufPluginTestHelper.verifyProjectDir(projectDir) where: - [gradleVersion, kotlinVersion] << [GRADLE_VERSIONS, KOTLIN_VERSIONS].combinations() + gradleVersion << GRADLE_VERSIONS + kotlinVersion << KOTLIN_VERSIONS } @Unroll @@ -219,7 +220,8 @@ class ProtobufJavaPluginTest extends Specification { ProtobufPluginTestHelper.verifyProjectDir(projectDir) where: - [gradleVersion, kotlinVersion] << [GRADLE_VERSIONS, KOTLIN_VERSIONS].combinations() + gradleVersion << GRADLE_VERSIONS + kotlinVersion << KOTLIN_VERSIONS } @Unroll