Skip to content

Commit

Permalink
Enable the sourceSets group for IntelliJ to recognize the generated J…
Browse files Browse the repository at this point in the history
…ava and Kotlin sources.

Subsequently, configure ktlint to avoid checking generated directories as a whole.
  • Loading branch information
nkhoshini authored and jamesward committed Feb 3, 2023
1 parent 8b865f7 commit 327bb93
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions examples/stub/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -22,24 +34,29 @@ 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")
main.java.srcDirs("build/generated/source/proto/main/grpc")
main.java.srcDirs("build/generated/source/proto/main/kotlin")
main.java.srcDirs("build/generated/source/proto/main/grpckt")
}
*/

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}

tasks.named("runKtlintCheckOverMainSourceSet").configure { dependsOn("generateProto") }
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
filter {
exclude {
it.file.path.contains("$buildDir/generated/")
}
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
kotlinOptions {
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
Expand Down

0 comments on commit 327bb93

Please sign in to comment.