Skip to content

Instantly share code, notes, and snippets.

@rakshitsoni02
Last active June 12, 2024 13:21
Show Gist options
  • Save rakshitsoni02/24368cefab507a4688b7f098fb2821f1 to your computer and use it in GitHub Desktop.
Save rakshitsoni02/24368cefab507a4688b7f098fb2821f1 to your computer and use it in GitHub Desktop.
Groovy to kotlin migration build logic, sample for conventional plugins
import com.android.build.api.dsl.ApplicationExtension
import com.orgname.samples.plugins.APP_TARGET_SDK_VERSION
import com.orgname.samples.plugins.configureKotlinAndroid
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
class AndroidApplicationConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.application")
apply("org.jetbrains.kotlin.android")
apply("orgname.android.lint")
}
extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = APP_TARGET_SDK_VERSION
@Suppress("UnstableApiUsage")
testOptions.animationsDisabled = true
}
}
}
}
import com.android.build.gradle.LibraryExtension
import com.orgname.samples.plugins.APP_TARGET_SDK_VERSION
import com.orgname.samples.plugins.configureKotlinAndroid
import com.orgname.samples.plugins.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.kotlin
class AndroidLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
apply("orgname.android.lint")
}
extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = APP_TARGET_SDK_VERSION
testOptions.animationsDisabled = true
}
dependencies {
add("testImplementation", kotlin("test"))
add("implementation", libs.findLibrary("androidx.tracing.ktx").get())
}
}
}
}
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.gradle.LibraryExtension
import com.orgname.samples.plugins.configureAndroidCompose
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
class ComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
val extension =
project.extensions.findByType(LibraryExtension::class.java)
?: extensions.getByType<ApplicationExtension>()
configureAndroidCompose(extension, true)
}
}
}
import com.orgname.samples.plugins.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
class DaggerConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.devtools.ksp")
}
dependencies {
add("implementation", libs.findLibrary("dagger").get())
add("ksp", libs.findLibrary("dagger-compiler").get())
}
}
}
}
import com.orgname.samples.plugins.configureKotlinJvm
import org.gradle.api.Plugin
import org.gradle.api.Project
class JvmLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.jvm")
apply("orgname.android.lint")
}
configureKotlinJvm()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment