Skip to content

Commit

Permalink
Update dependencies & Move build logic to convention plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ARTI1208 committed Dec 8, 2023
1 parent c24d537 commit 04a6587
Show file tree
Hide file tree
Showing 96 changed files with 557 additions and 658 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- run: chmod +x gradlew
- name: Build debug
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- run: chmod +x gradlew
- name: Build release
Expand All @@ -36,7 +36,7 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- name: Extract changelog
id: extract_changelog
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
- name: Run static analysis
uses: natiginfo/action-detekt-all@1.22.0-RC1
uses: natiginfo/action-detekt-all@1.23.1
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- run: chmod +x gradlew
- name: Unit test
Expand Down
18 changes: 6 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ import com.android.build.api.dsl.PostProcessing
import com.android.build.api.dsl.VariantDimension
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import org.jetbrains.kotlin.konan.properties.hasProperty
import ru.art2000.modules.setupAndroidModule
import ru.art2000.modules.kapt
import java.util.*

plugins {
id("com.android.application")
id("kotlin-android")
id("convention.android")
}

setupAndroidModule()

val major = 1
val minor = 5
val patch = 4
val code = 18

android {
namespace = "ru.art2000.calculator"

signingConfigs {
create("release") {

Expand Down Expand Up @@ -89,7 +86,7 @@ android {
}
}

val newVersion = tasks.create("newVersion") {
tasks.create("newVersion") {

val version = "v${android.defaultConfig.versionName}"

Expand Down Expand Up @@ -129,17 +126,14 @@ val newVersion = tasks.create("newVersion") {

dependencies {
implementation(fileTree("include" to listOf("*.jar"), "dir" to "libs"))
implementation(project(":shared"))
implementation(projects.shared)

implementation(libs.constraintlayout)
implementation(libs.bundles.hilt.impl)
kapt(libs.bundles.hilt.kapt)
implementation(libs.lifecycle.viewmodel)

implementation(libs.viewbindingdelegate)

debugImplementation(libs.leakcanary)

"minApi21Implementation"(libs.bundles.compose)

}
}
15 changes: 1 addition & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.dagger) apply false
}

buildscript {
repositories {
google()
Expand All @@ -11,6 +6,7 @@ buildscript {
dependencies {
classpath(libs.android.gradle)
classpath(libs.kotlin.gradle)
classpath(libs.dagger.gradle)
}
}

Expand All @@ -20,13 +16,4 @@ allprojects {
mavenCentral()
maven("https://jitpack.io")
}
tasks.withType<JavaCompile> {
options.compilerArgs.plusAssign(listOf(
"-Xlint:unchecked", "-Xlint:deprecation"
))
}
}

tasks.create("clean", Delete::class.java) {
delete(rootProject.buildDir)
}
19 changes: 10 additions & 9 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
plugins {
`kotlin-dsl`
java
}

fun library(alias: String) =
extensions.getByType<VersionCatalogsExtension>()
.named("libs")
.findLibrary(alias)
.get()

dependencies {
implementation(library("android-gradle"))
implementation(library("kotlin-gradle"))
implementation(library("javapoet"))
implementation(libs.android.gradle)
implementation(libs.kotlin.gradle)
implementation(libs.ksp.gradle)
implementation(libs.dagger.gradle)
// compileClasspath(libs.dagger.gradle)
// kotlinCompilerClasspath(libs.dagger.gradle)
implementation(libs.javapoet)
// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}

repositories {
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rootProject.name = "buildSrc"

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
Expand Down
175 changes: 175 additions & 0 deletions buildSrc/src/main/kotlin/convention.android.base.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import com.android.build.api.dsl.ComposeOptions
import com.android.build.api.dsl.ProductFlavor
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.gradle.internal.TaskManager
import com.android.build.gradle.internal.component.ComponentCreationConfig
import com.android.build.gradle.internal.dsl.DefaultConfig
import com.android.build.gradle.internal.dsl.InternalCommonExtension
import com.android.build.gradle.internal.utils.addComposeArgsToKotlinCompile
import org.gradle.accessors.dm.LibrariesForLibs
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.base")
}

val libs = the<LibrariesForLibs>()
val javaVersion = JavaVersion.toVersion(libs.versions.java.get())

android {

namespace = "ru.art2000.calculator.${project.name}"
compileSdk = 34

defaultConfig {
minSdk = 16
targetSdk = 34

multiDexEnabled = true
vectorDrawables.useSupportLibrary = true
}

buildFeatures {
viewBinding = true
buildConfig = true
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
}
testOptions {
unitTests.all {
it.useJUnitPlatform()
}
}

flavorDimensions += listOf("sdk")
productFlavors {

create("minApi16") {
minSdk = 16
dimension = "sdk"
}

create("minApi21") {
minSdk = 21
dimension = "sdk"
addCompose(this) {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
}
}
compileOptions {
targetCompatibility = javaVersion
sourceCompatibility = javaVersion
}
}

kotlin<KotlinProjectExtension> {
jvmToolchain(javaVersion.majorVersion.toInt())

// Nevertheless it is applied in kmp convention plugin, code below is run before
// and we need android source set to add dependencies in this plugin
if (this is KotlinMultiplatformExtension) {
androidTarget()
}
}

dependencies {
val implementationConfigurationName = when (val extension = kotlin as? KotlinMultiplatformExtension) {
null -> "implementation"
else -> extension.sourceSets.getByName("androidMain").implementationConfigurationName
}

fun unifiedImplementation(dependencyNotation: Any) {
add(implementationConfigurationName, dependencyNotation)
}

unifiedImplementation(libs.androidx.core)
unifiedImplementation(libs.appcompat)
unifiedImplementation(libs.fragment)
unifiedImplementation(libs.preference)
unifiedImplementation(libs.recycler)
unifiedImplementation(libs.material)
unifiedImplementation(libs.multidex)

"coreLibraryDesugaring"(libs.desugaring)
"minApi21Implementation"(libs.bundles.compose)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

// ===== Utils =====================================================================================

fun Project.addCompose(flavor: ProductFlavor, options: ComposeOptions.() -> Unit = {}) {

val composeOptions = object : ComposeOptions {
override var kotlinCompilerExtensionVersion: String? = null

@Deprecated("")
override var kotlinCompilerVersion: String?
get() = null
set(_) { logger.warn("ComposeOptions.kotlinCompilerVersion is deprecated. Compose now uses the kotlin compiler defined in your buildscript.") }

override var useLiveLiterals: Boolean= true

}

composeOptions.options()

// adapted from [com.android.build.gradle.internal.TaskManager]

val kotlinCompilerExtensionVersionInDsl =
composeOptions.kotlinCompilerExtensionVersion

val useLiveLiterals = composeOptions.useLiveLiterals

// Create a project configuration that holds the androidx compose kotlin
// compiler extension
val kotlinExtension = project.configurations.create("kotlin-extension")
project.dependencies
.add(
kotlinExtension.name, "androidx.compose.compiler:compiler:"
+ (kotlinCompilerExtensionVersionInDsl
?: TaskManager.COMPOSE_KOTLIN_COMPILER_EXTENSION_VERSION))
kotlinExtension.isTransitive = false
kotlinExtension.description = "Configuration for Compose related kotlin compiler extension"

extensions.configure<AndroidComponentsExtension<*, *, *>>("androidComponents") {
onVariants {
if (it.flavorName != flavor.name) return@onVariants

val creationConfig = it as ComponentCreationConfig

val taskNamePrefix = creationConfig.computeTaskName("compile")
val possibleTaskNames = listOf(
"${taskNamePrefix}Kotlin",
"${taskNamePrefix}KotlinAndroid",
)

project.tasks.whenTaskAdded {
if (name !in possibleTaskNames) return@whenTaskAdded

addComposeArgsToKotlinCompile(
this as KotlinCompile,
creationConfig,
project.files(kotlinExtension),
useLiveLiterals,
)
}
}
}
}

fun android(configure: Action<InternalCommonExtension<*, *, DefaultConfig, *, *>>) =
extensions.configure("android", configure)

val Project.kotlin: KotlinProjectExtension
get() = extensions.getByName("kotlin") as KotlinProjectExtension

fun <T : KotlinProjectExtension> Project.kotlin(configure: Action<T>) =
extensions.configure("kotlin", configure)
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/convention.android.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
kotlin("android")
id("com.android.application")
id("convention.android.base")
id("com.google.devtools.ksp")
id("convention.dagger")
}
Loading

0 comments on commit 04a6587

Please sign in to comment.