Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using kotlin build scripts. #22

Merged
merged 7 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ There are also templates within this template. This repo comes shipped with a [P

## Dependency Setup

You may notice that dependencies are set up in a very specific way. Each of the tools has its own Gradle file in the [buildscripts folder](/buildscripts). This is by design so that if you chose to have a multi module project, these dependencies can easily be shared between them. This is already configured inside our root `build.gradle` file, by applying to each sub project:
You may notice that dependencies are set up in a very specific way. Each of the tools has its own Gradle file in the [buildscripts folder](/buildscripts). This is by design so that if you chose to have a multi module project, these dependencies can easily be shared between them. This is already configured inside our root `build.gradle.kts` file, by applying to each sub project:

```groovy
subprojects {
Expand Down
42 changes: 23 additions & 19 deletions app/build.gradle → app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
plugins {
id "com.android.application"
id "kotlin-android"
id("com.android.application")
id("kotlin-android")
}

android {
compileSdk 33
compileSdk = 33

defaultConfig {
applicationId "template.app.id"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
applicationId = "template.app.id"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
useSupportLibrary = true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

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

kotlinOptions {
jvmTarget = "1.8"
}

buildFeatures {
compose true
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion "1.3.0"
kotlinCompilerVersion kotlinVersion
kotlinCompilerExtensionVersion = "1.3.0"
}

packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand All @@ -47,7 +51,7 @@ android {
}

dependencies {
def composeBom = platform(libs.compose.bom)
val composeBom = platform(libs.compose.bom)
implementation(composeBom)
debugImplementation(composeBom)
androidTestImplementation(composeBom)
Expand All @@ -68,4 +72,4 @@ dependencies {
androidTestImplementation(libs.compose.ui.test.junit)

debugImplementation(libs.compose.ui.tooling)
}
}
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
50 changes: 0 additions & 50 deletions build.gradle

This file was deleted.

52 changes: 52 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
extra.apply {
set("kotlinVersion", "1.7.10")

// https://github.com/JLLeitschuh/ktlint-gradle/releases
set("ktlintPluginVersion", "11.0.0")

// https://github.com/detekt/detekt/releases
set("detektVersion", "1.21.0")

// https://github.com/ben-manes/gradle-versions-plugin
set("versionsPluginVersion", "0.42.0")
}

repositories {
google()
mavenCentral()
maven(url = "https://plugins.gradle.org/m2/")
}

dependencies {
classpath("com.android.tools.build:gradle:7.2.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra.get("kotlinVersion")}")
classpath("org.jlleitschuh.gradle:ktlint-gradle:${rootProject.extra.get("ktlintPluginVersion")}")
classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${rootProject.extra.get("detektVersion")}")
classpath("com.github.ben-manes:gradle-versions-plugin:${rootProject.extra.get("versionsPluginVersion")}")

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

apply(from = "buildscripts/githooks.gradle")
apply(from = "buildscripts/setup.gradle")

subprojects {
apply(from = "../buildscripts/ktlint.gradle")
apply(from = "../buildscripts/detekt.gradle")
apply(from = "../buildscripts/versionsplugin.gradle")
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}

afterEvaluate {
// We install the hook at the first occasion
tasks.named("clean") {
dependsOn(":installGitHooks")
}
}
12 changes: 6 additions & 6 deletions buildscripts/setup.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ task replacePackageInManifest {
}

task replaceApplicationId {
description "Replaces application ID in app/build.gradle file."
description "Replaces application ID in app/build.gradle.kts file."
group null

doLast {
def file = new File("${rootDir}/app/build.gradle")
def file = new File("${rootDir}/app/build.gradle.kts")

file.text = file.text.replaceAll(
"applicationId \"${renameConfig.templateAppId}\"",
"applicationId \"${renameConfig.newPackage}\"",
"applicationId = \"${renameConfig.templateAppId}\"",
"applicationId = \"${renameConfig.newPackage}\"",
)
}
}

task replaceProjectName {
description "Replaces project name in settings.gradle file."
description "Replaces project name in settings.gradle.kts file."
group null

doLast {
def file = new File("${rootDir}/settings.gradle")
def file = new File("${rootDir}/settings.gradle.kts")

file.text = file.text.replaceAll(
"rootProject.name = \"${renameConfig.templateName}\"",
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle → settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dependencyResolutionManagement {
}
}
rootProject.name = "template"
include ':app'
include(":app")