Skip to content

Commit

Permalink
Update, Kotlin Compile / Project Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluu committed May 2, 2023
1 parent 462fe1b commit ff33a49
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
8 changes: 8 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}
Expand All @@ -9,6 +11,12 @@ java {
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
configureAndroid()

extensions.configure<BaseAppModuleExtension> {
configureKotlin(this)
configureKotlin()

signingConfigs {
getByName("debug") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
configureAndroid()

extensions.configure<LibraryExtension> {
configureKotlin(this)
configureKotlin()

lint {
checkOnly.add("Interoperability")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.io.File
* Configure Compose-specific options
*/
internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *>,
) {
val libs = findVersionCatalog()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ object Const {
const val compileSdk = 33
const val minSdk = 21
const val targetSdk = 33
const val JDK_VERSION = 17
val JAVA_VERSION = JavaVersion.VERSION_17
const val JDK_VERSION = 11
val JAVA_VERSION = JavaVersion.VERSION_11
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KaptExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/**
* Configure base Kotlin with Android options
Expand All @@ -36,20 +38,20 @@ internal fun Project.configureAndroid() {
}
}

internal fun Project.configureKotlin(
commonExtension: CommonExtension<*, *, *, *>
) {
commonExtension.kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xskip-prerelease-check",
"-Xjvm-default=all",
// Enable experimental coroutines APIs, including Flow
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
)
internal fun Project.configureKotlin() {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
// Set JVM target
jvmTarget = Const.JAVA_VERSION.toString()
// allWarningsAsErrors = true

// Set JVM target
jvmTarget = Const.JAVA_VERSION.toString()
allWarningsAsErrors = true
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xskip-prerelease-check",
"-Xjvm-default=all",
// Enable experimental coroutines APIs, including Flow
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
)
}
}
}

Expand All @@ -71,7 +73,7 @@ internal fun Project.`kotlin`(
(this as ExtensionAware).extensions.configure("kotlin", configure)
}

internal fun CommonExtension<*, *, *, *>.kotlinOptions(
internal fun CommonExtension<*, *, *, *, *>.kotlinOptions(
configure: KotlinJvmOptions.() -> Unit
) {
(this as ExtensionAware).extensions.configure("kotlinOptions", configure)
Expand Down

0 comments on commit ff33a49

Please sign in to comment.