Skip to content

Commit

Permalink
Move Java/Kotlin compat to the convention plugin.
Browse files Browse the repository at this point in the history
This was apparently only ever in the gradle scripts for projects that
used Kotlin. I don't know if it's necessary for Java projects, but it's
likely not harmful? For Kotlin projects these versions all need to
match.

It's actually possible for us to bump this to Java 11, by the look of
things (see the Now In Android link below). For now I'm keeping things
the way they are.

https://github.com/android/nowinandroid/blob/7f2ce57c67c68aa921de9231525a4a47ef431fe8/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt#L63
  • Loading branch information
DanAlbert committed May 9, 2024
1 parent 46f4a2b commit a4b082d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tasks.withType<KotlinCompile>().configureEach {

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
}

gradlePlugin {
Expand All @@ -27,5 +28,9 @@ gradlePlugin {
id = "ndksamples.android.application"
implementationClass = "com.android.ndk.samples.buildlogic.AndroidApplicationConventionPlugin"
}
register("kotlinAndroid") {
id = "ndksamples.android.kotlin"
implementationClass = "com.android.ndk.samples.buildlogic.KotlinConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
minSdk = Versions.MIN_SDK
targetSdk = Versions.TARGET_SDK
}
compileOptions {
sourceCompatibility = Versions.JAVA
targetCompatibility = Versions.JAVA
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.android.ndk.samples.buildlogic

import com.android.build.api.dsl.ApplicationExtension

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

class KotlinConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.android")
}

extensions.configure<ApplicationExtension> {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = Versions.JAVA.toString()
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.android.ndk.samples.buildlogic

import org.gradle.api.JavaVersion

object Versions {
const val COMPILE_SDK = 34
const val TARGET_SDK = 34
const val MIN_SDK = 21
const val NDK = "26.3.11579264" // r26d
val JAVA = JavaVersion.VERSION_1_8
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitV
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }

# build-logic dependencies
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
Expand Down

0 comments on commit a4b082d

Please sign in to comment.