Skip to content

Commit

Permalink
Gradle improvements (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
evant authored Dec 21, 2022
1 parent 4f08ef5 commit cb80c6c
Show file tree
Hide file tree
Showing 30 changed files with 265 additions and 710 deletions.
18 changes: 1 addition & 17 deletions app-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
plugins {
id("com.android.application")
id("social.androiddev.android.common")
kotlin("android")
id("org.jetbrains.compose")
id("kotlin-parcelize")
id("social.androiddev.code-quality")
}

val targetSDKVersion: Int by rootProject.extra
val minSDKVersion: Int by rootProject.extra
val compileSDKVersion: Int by rootProject.extra

android {
namespace = "social.androiddev.dodo"
compileSdk = compileSDKVersion

defaultConfig {
minSdk = minSDKVersion
targetSdk = targetSDKVersion
versionCode = 1
versionName = "1.0"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "11"
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion app-desktop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
id("social.androiddev.codequality")
kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22)
id("org.jetbrains.compose")
id("social.androiddev.code-quality")
}

kotlin {
Expand Down
14 changes: 5 additions & 9 deletions build-logic/convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ plugins {
`kotlin-dsl`
}

gradlePlugin {
plugins {
register("CodeQuality") {
id = "social.androiddev.code-quality"
implementationClass = "social.androiddev.plugins.CodeQualityPlugin"
}
}
}

dependencies {
implementation(libs.com.diffplug.spotless.gradle.plugin)
implementation(libs.org.jetbrains.kotlin.gradle.plugin)
implementation(libs.org.jetbrains.compose.gradle.plugin)
implementation(libs.com.android.tools.build.gradle)
// hack to access version catalogue https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Convention plugin to apply android configuration that's common across both library and app
* modules.
*/
plugins {
id("social.androiddev.codequality")
}

android {
compileSdk = 33

defaultConfig {
minSdk = 33
}

// targetSdk is in a different interface for library and application projects
when (this) {
is com.android.build.api.dsl.ApplicationBaseFlavor -> {
targetSdk = 33
}
is com.android.build.api.dsl.LibraryBaseFlavor -> {
targetSdk = 33
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}

fun Project.android(configure: com.android.build.api.dsl.CommonExtension<*, *, *, *>.() -> Unit) {
extensions.configure("android", configure)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Convention plugin to apply various code-quality tools. Since this should be included in every
* module, it's applied automatically by other convention plugins, but can be applied directly for
* any module that doesn't use any.
*/
plugins {
id("com.diffplug.spotless")
}

spotless {
kotlin {
target("src/*/kotlin/**/*.kt")
ktlint("0.43.2")
licenseHeaderFile(File(rootDir, "copyright.txt"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Convention plugin to apply common configurations for library modules. Instead of depending on
* this directly you should depend on `social.androiddev.library` or `social.androiddev.library.ui`.
*/
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("com.android.library")
id("social.androiddev.android.common")
}

android {
sourceSets {
named("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/res")
}
}
}

// Workaround for:
//
// The Kotlin source set androidAndroidTestRelease was configured but not added to any
// Kotlin compilation. You can add a source set to a target's compilation by connecting it
// with the compilation's default source set using 'dependsOn'.
// See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
//
// Remove log pollution until Android support in KMP improves.
//
afterEvaluate {
project.extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.let { ext ->
ext.sourceSets.removeAll { sourceSet ->
setOf(
"androidAndroidTestRelease",
"androidTestFixtures",
"androidTestFixturesDebug",
"androidTestFixturesRelease",
).contains(sourceSet.name)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Convention plugin for non-ui library modules.
*/
plugins {
id("social.androiddev.library.common")
}

val libs = the<org.gradle.accessors.dm.LibrariesForLibs>()

kotlin {
jvm("desktop")
android()
ios()

sourceSets {
// shared
val commonMain by getting

val androidMain by getting {
dependsOn(commonMain)
}

// testing
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.org.jetbrains.kotlin.test.common)
implementation(libs.org.jetbrains.kotlin.test.annotations.common)
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.org.jetbrains.kotlin.test.junit)
}
}
val desktopTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.org.jetbrains.kotlin.test.junit)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Convention plugin for ui library modules. Includes compose dependencies. Currently does not
* support iOS.
*/
plugins {
id("social.androiddev.library.common")
id("org.jetbrains.compose")
}

val libs = the<org.gradle.accessors.dm.LibrariesForLibs>()

kotlin {
jvm("desktop")
android()

sourceSets {
// shared
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
}
}

// android
val androidMain by getting {
dependencies {
implementation(libs.androidx.core.ktx)
// Workaround for https://github.com/JetBrains/compose-jb/issues/2340
implementation(libs.androidx.compose.foundation)
}
}

// desktop
val desktopMain by getting {
dependencies {
implementation(compose.desktop.common)
}
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ rootProject.name = "build-logic"

dependencyResolutionManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
google()
}
versionCatalogs {
create("libs") {
Expand Down
30 changes: 1 addition & 29 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
buildscript {

extra["targetSDKVersion"] = 33
extra["compileSDKVersion"] = 33
extra["minSDKVersion"] = 23

repositories {
google()
mavenCentral()
Expand All @@ -18,28 +14,4 @@ buildscript {
classpath(libs.com.google.osdetector.gradle.plugin)
classpath(libs.org.jetbrains.kotlinx.atomicfu.plugin)
}
}

// Workaround for:
//
// The Kotlin source set androidAndroidTestRelease was configured but not added to any
// Kotlin compilation. You can add a source set to a target's compilation by connecting it
// with the compilation's default source set using 'dependsOn'.
// See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
//
// Remove log pollution until Android support in KMP improves.
//
subprojects {
afterEvaluate {
project.extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.let { ext ->
ext.sourceSets.removeAll { sourceSet ->
setOf(
"androidAndroidTestRelease",
"androidTestFixtures",
"androidTestFixturesDebug",
"androidTestFixturesRelease",
).contains(sourceSet.name)
}
}
}
}
}
Loading

0 comments on commit cb80c6c

Please sign in to comment.