Skip to content

Commit

Permalink
Upgrade to Gradle Version Catalogs, convention plugins. Move sourcese…
Browse files Browse the repository at this point in the history
…t from java to kotlin, and upgrade build scripts.
  • Loading branch information
oliverspryn committed Feb 7, 2024
1 parent 87629ae commit 6491bed
Show file tree
Hide file tree
Showing 66 changed files with 964 additions and 477 deletions.
21 changes: 20 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
[*]
[*.{kt,kts}]
# https://pinterest.github.io/ktlint/latest/rules/configuration-ktlint/#code-style
ktlint_code_style = intellij_idea

#############################################

# https://pinterest.github.io/ktlint/latest/rules/configuration-ktlint/#final-newline
insert_final_newline = true

# https://pinterest.github.io/ktlint/latest/rules/standard/#trailing-comma-on-declaration-site
ij_kotlin_allow_trailing_comma = false

# https://pinterest.github.io/ktlint/latest/rules/standard/#trailing-comma-on-call-site
ij_kotlin_allow_trailing_comma_on_call_site = false

# https://pinterest.github.io/ktlint/latest/rules/standard/#no-wildcard-imports
ij_kotlin_packages_to_use_import_on_demand = unset # Disallows all wildcard imports

# https://pinterest.github.io/ktlint/latest/rules/standard/#import-ordering
# https://pinterest.github.io/ktlint/latest/rules/standard/#no-wildcard-imports
ij_kotlin_imports_layout = * # Alphabetical with capital letters before lower case letters (e.g. Z before a), no blank lines
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Build with Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v3
with:
arguments: build
10 changes: 5 additions & 5 deletions .github/workflows/publish-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Build the Dokka Documentation
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v3
with:
arguments: dokkaHtmlMultiModule

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle

Expand All @@ -31,6 +31,6 @@ jobs:
GPG_SIGNING_KEY_PASSWORD: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}

- name: Publish the Library
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v3
with:
arguments: publishMultimodalSpannerPublicationToCentralRepository
5 changes: 0 additions & 5 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 5 additions & 84 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,91 +1,12 @@
plugins {
id("com.android.application")
id("com.google.dagger.hilt.android")
kotlin("android")
kotlin("kapt")
}

android {
compileSdk = Versions.COMPILE_SDK
namespace = "${Config.APPLICATION_ID}.sample"

defaultConfig {
applicationId = "${Config.APPLICATION_ID}.sample"

minSdk = Versions.MIN_SDK
targetSdk = Versions.TARGET_SDK

versionCode = Versions.VERSION_CODE
versionName = Versions.VERSION_NAME

vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
getByName("debug") {
isMinifyEnabled = false
isTestCoverageEnabled = true
}

getByName("release") {
isMinifyEnabled = false
isShrinkResources = false
}
}

compileOptions {
sourceCompatibility = Versions.JVM
targetCompatibility = Versions.JVM
}

kotlinOptions {
jvmTarget = Versions.JVM_STRING
}
alias(libs.plugins.multimodal.app)

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = Versions.COMPOSE_COMPILER
}

packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
alias(libs.plugins.multimodal.compose.app)
alias(libs.plugins.multimodal.hilt)
}

dependencies {
api(platform(project(":constraints")))
api(project(":multimodal"))
kapt(platform(project(":constraints")))

/////////////////////////////////////////////////////////////////////

// region Application

debugImplementation(Libraries.COMPOSE_MANIFEST_TEST)
debugImplementation(Libraries.COMPOSE_UI_TOOLING)

implementation(Libraries.ACTIVITY_COMPOSE)
implementation(Libraries.COMPOSE_UI)
implementation(Libraries.COMPOSE_UI_TOOLING_PREVIEW)
implementation(Libraries.CORE_KTX)
implementation(Libraries.DAGGER_ANDROID)
implementation(Libraries.MATERIAL)
implementation(Libraries.MATERIAL_3)
implementation(Libraries.NAVIGATION_COMPOSE)
implementation(Libraries.WINDOW_MANAGER)

kapt(Libraries.DAGGER_COMPILER)

// endregion
}
implementation(project(":multimodal"))

kapt {
correctErrorTypes = true
implementation(libs.material)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun MultimodalSpannerTheme(
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
//ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
}
}

Expand Down
2 changes: 2 additions & 0 deletions build-logic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/*/build
34 changes: 34 additions & 0 deletions build-logic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Convention Plugins

The `build-logic` folder defines project-specific convention plugins, used to keep a single source
of truth for common module configurations.

This approach is heavily based on these articles and/or repositories:

- [Now in Android](https://github.com/android/nowinandroid/tree/main/build-logic)
- [Unlocking Reusability in Gradle: How to Use Kotlin-written Convention
Plugins](https://medium.com/@amsavarthan/11b95cb008ef)
- [Mastering Dependency Management: Version Catalog & Convention Plugin at
Scale](https://proandroiddev.com/b94205595f6b)
- [Using Version Catalogs from Gradle Precompiled Scripts with Kotlin
DSL](https://medium.com/@saulmm2/df3c27ea017c)

By setting up convention plugins in `build-logic`, we can avoid duplicated build script setup,
messy `subproject` configurations, without the pitfalls of the `buildSrc` directory.

`build-logic` is an included build, as configured in the root
[`settings.gradle.kts`](../settings.gradle.kts).

Inside `build-logic` is a `convention` module, which defines a set of plugins that all other
modules can use to configure themselves.

`build-logic` also includes a set of `Kotlin` files used to share logic between plugins themselves,
which is most useful for configuring Android components (libraries vs applications) with shared
code.

These plugins are *additive* and *composable*, and try to only accomplish a single responsibility.
Modules can then pick and choose the configurations they need.

If there is one-off logic for a module without shared code, it's preferable to define that directly
in the module's `build.gradle.kts`, as opposed to creating a convention plugin with module-specific
setup.
65 changes: 65 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

group = "com.oliverspryn.gradle"

// Configure the build-logic plugins to target JDK 17
// This matches the JDK used to build the project, and is not related to what is running on device.
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

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

dependencies {
compileOnly(libs.agp)
compileOnly(libs.dokka)
compileOnly(libs.kotlin)
}

gradlePlugin {
plugins {
register("app") {
id = "multimodal.app"
implementationClass = "com.oliverspryn.gradle.plugin.AndroidApplicationConventionPlugin"
}

register("compose-app") {
id = "multimodal.compose-app"
implementationClass = "com.oliverspryn.gradle.plugin.ComposeApplicationConventionPlugin"
}

register("compose-library-base") {
id = "multimodal.compose-library-base"
implementationClass = "com.oliverspryn.gradle.plugin.BaseComposeLibraryConventionPlugin"
}

register("dokka") {
id = "multimodal.dokka"
implementationClass = "com.oliverspryn.gradle.plugin.DokkaConventionPlugin"
}

register("hilt") {
id = "multimodal.hilt"
implementationClass = "com.oliverspryn.gradle.plugin.HiltConventionPlugin"
}

register("library") {
id = "multimodal.library"
implementationClass = "com.oliverspryn.gradle.plugin.AndroidLibraryConventionPlugin"
}

register("publish") {
id = "multimodal.publish"
implementationClass = "com.oliverspryn.gradle.plugin.PublishConventionPlugin"
}
}
}
Loading

0 comments on commit 6491bed

Please sign in to comment.