Skip to content

Instantly share code, notes, and snippets.

@hkhc
Created May 22, 2021 10:10
Show Gist options
  • Save hkhc/94782be4d716fd307e3c98870854a9da to your computer and use it in GitHub Desktop.
Save hkhc/94782be4d716fd307e3c98870854a9da to your computer and use it in GitHub Desktop.
build.gradle.kts show errors in Android Studio
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
plugins {
kotlin("jvm")
id("org.jlleitschuh.gradle.ktlint")
id("io.gitlab.arturbosch.detekt")
id("io.hkhc.jarbird")
// for build script debugging
id("org.barfuin.gradle.taskinfo")
}
/*
It is needed to make sure every version of java compiler to generate same kind of bytecode.
Without it and build this with java 8+ compiler, then the project build with java 8
will get error like this:
> Unable to find a matching variant of <your-artifact>:
- Variant 'apiElements' capability <your-artifact>:
- Incompatible attributes:
- Required org.gradle.jvm.version '8' and found incompatible value '13'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
...
*/
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks {
/*
Without this Kotlin generates java 6 bytecode, which is hardly fatal.
*/
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
// dokka {
// outputFormat = "html"
// outputDirectory = "$buildDir/dokka"
// }
}
ktlint {
debug.set(true)
verbose.set(true)
android.set(true)
coloredOutput.set(true)
reporters {
setOf(ReporterType.CHECKSTYLE, ReporterType.PLAIN)
}
}
detekt {
config = files("default-detekt-config.yml")
}
dependencies {
implementation(Kotlin.stdlib)
testImplementation(Testing.junit4)
testImplementation("org.assertj:assertj-core:_")
testImplementation(Testing.mockK)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment