Abstract common build logic out to convention plugin

Convert some gradle files to kotlin
This is going to set us up for a shared basetest module which will enable us to stop duplicating test fixtures across test and androidtest
This commit is contained in:
Paul Klauser
2024-06-04 09:16:39 -04:00
parent d17dbf8459
commit 5780254ef9
12 changed files with 106 additions and 46 deletions

View File

@ -1,6 +1,5 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'vocable.application'
id 'kotlin-kapt'
id 'kotlin-parcelize'
id "androidx.navigation.safeargs.kotlin"
@ -10,11 +9,8 @@ plugins {
android {
namespace 'com.willowtree.vocable'
compileSdk 33
defaultConfig {
applicationId "com.willowtree.vocable"
minSdkVersion 24
targetSdkVersion 33
//30 was the last versionCode used on Play Store before implementing CI with github actions
versionCode Integer.valueOf(System.getenv("VERSION_CODE") ?: 1) + 30
versionName System.getenv("VERSION_NAME") ?: "pre-release" + "(" + versionCode + ")"
@ -45,13 +41,6 @@ android {
buildConfigField("boolean", "USE_HEAD_TRACKING", useHeadTracking)
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
viewBinding {
enabled = true
}
@ -67,8 +56,6 @@ android {
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'

1
build-logic/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,10 @@
plugins {
`kotlin-dsl`
}
group = "com.willowtree.vocable.buildlogic"
dependencies {
implementation(libs.android.gradlePlugin)
implementation(libs.kotlin.gradlePlugin)
}

View File

@ -0,0 +1,13 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
rootProject.name = "build-logic"

View File

@ -0,0 +1,27 @@
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
fun Project.commonAndroid(extension: CommonExtension<*, *, *, *, *, *>) {
pluginManager.apply("org.jetbrains.kotlin.android")
extension.apply {
compileSdk = 34
defaultConfig.minSdk = 24
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
freeCompilerArgs += listOf(
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
)
}
}
}

View File

@ -0,0 +1,5 @@
plugins {
id("com.android.application")
}
commonAndroid(android)

View File

@ -0,0 +1,5 @@
plugins {
id("com.android.library")
}
commonAndroid(android)

View File

@ -1,30 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.8.10'
repositories {
google()
maven { url "https://plugins.gradle.org/m2/" }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0"
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.safe.args) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.crashlytics) apply false
}

View File

@ -1,5 +1,19 @@
[versions]
turbine = "1.1.0"
kotlin = "1.8.10"
agp = "8.4.1"
safe-args = "2.6.0"
google-services = "4.3.15"
crashlytics = "2.8.1"
[libraries]
turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
safe-args = { id = "androidx.navigation.safeargs.kotlin", version.ref = "safe-args" }
google-services = { id = "com.google.gms.google-services", version.ref = "google-services" }
crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "crashlytics" }

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip

View File

@ -1 +0,0 @@
include ':app'

21
settings.gradle.kts Normal file
View File

@ -0,0 +1,21 @@
// Needed because of https://issuetracker.google.com/issues/315023802
gradle.startParameter.excludedTaskNames.addAll(listOf(":build-logic:testClasses"))
pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "vocable-android"
include(":app")