From 327bb93a4e66031793699821c1fa6f31a68a37b8 Mon Sep 17 00:00:00 2001 From: Nima Khoshini Date: Wed, 25 Jan 2023 15:12:01 -0800 Subject: [PATCH] Enable the sourceSets group for IntelliJ to recognize the generated Java and Kotlin sources. Subsequently, configure ktlint to avoid checking generated directories as a whole. --- examples/stub/build.gradle.kts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/stub/build.gradle.kts b/examples/stub/build.gradle.kts index 8d6a6867..29db417a 100644 --- a/examples/stub/build.gradle.kts +++ b/examples/stub/build.gradle.kts @@ -3,6 +3,18 @@ import com.google.protobuf.gradle.id import com.google.protobuf.gradle.plugins import com.google.protobuf.gradle.protobuf import com.google.protobuf.gradle.protoc +import org.gradle.kotlin.dsl.api +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.ext +import org.gradle.kotlin.dsl.getValue +import org.gradle.kotlin.dsl.getting +import org.gradle.kotlin.dsl.invoke +import org.gradle.kotlin.dsl.java +import org.gradle.kotlin.dsl.kotlin +import org.gradle.kotlin.dsl.project +import org.gradle.kotlin.dsl.sourceSets +import org.gradle.kotlin.dsl.withType plugins { kotlin("jvm") @@ -22,9 +34,6 @@ dependencies { api("io.grpc:grpc-kotlin-stub:${rootProject.ext["grpcKotlinVersion"]}") } -/* -// this makes it so IntelliJ picks up the sources but then ktlint complains - sourceSets { val main by getting { } main.java.srcDirs("build/generated/source/proto/main/java") @@ -32,7 +41,6 @@ sourceSets { main.java.srcDirs("build/generated/source/proto/main/kotlin") main.java.srcDirs("build/generated/source/proto/main/grpckt") } - */ java { toolchain { @@ -40,6 +48,15 @@ java { } } +tasks.named("runKtlintCheckOverMainSourceSet").configure { dependsOn("generateProto") } +configure { + filter { + exclude { + it.file.path.contains("$buildDir/generated/") + } + } +} + tasks.withType().all { kotlinOptions { freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")