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

[feat] create build-logic and implement custom convention plugin, modularize #9

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
88 changes: 6 additions & 82 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,88 +1,12 @@

plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.ktlint)
alias(libs.plugins.detekt)
alias(libs.plugins.spotless)
}
alias(libs.plugins.misik.application)
alias(libs.plugins.misik.android.hilt)

val ktlintVersion = "0.50.0"
}

android {
namespace = "com.nexters.misik"
compileSdk = 35

defaultConfig {
applicationId = "com.nexters.misik"
minSdk = 24
targetSdk = 35
versionCode = 1
versionName = "1.0"

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

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}

detekt {
config.from("${projectDir}/config/detekt/detekt-config.yml")
buildUponDefaultConfig = true
debug = true
}

spotless {
kotlin {
target("**/*.kt")
targetExclude("**/build/**/*.kt")
ktlint(ktlintVersion)
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".MisikApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/nexters/misik/MisikApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.nexters.misik

import android.app.Application
import androidx.multidex.BuildConfig
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

@HiltAndroidApp
class MisikApplication : Application() {
override fun onCreate() {
super.onCreate()

initTimber()
}

private fun initTimber() {
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}
}
1 change: 1 addition & 0 deletions build-logic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
1 change: 1 addition & 0 deletions build-logic/convention/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
73 changes: 73 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
plugins {
`kotlin-dsl`
}

group = "com.nexters.misik.convention"

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

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


dependencies {
compileOnly(libs.android.gradle.plugin)
compileOnly(libs.kotlin.gradle.plugin)
compileOnly(libs.ksp.gradle.plugin)
compileOnly(libs.compose.compiler.extension)
}

gradlePlugin {
plugins {
register("androidApplication") {
id = "misik.android.application"
implementationClass = "AndroidApplicationPlugin"
}

register("misikFeature") {
id = "misik.feature"
implementationClass = "MisikFeaturePlugin"
}

register("misikData") {
id = "misik.data"
implementationClass = "MisikDataPlugin"
}

register("androidLibrary") {
id = "misik.android.library"
implementationClass = "AndroidLibraryPlugin"
}

register("androidComposeLibrary") {
id = "misik.android.compose.library"
implementationClass = "AndroidComposeLibraryPlugin"
}

register("androidHilt") {
id = "misik.android.hilt"
implementationClass = "HiltPlugin"
}

register("javaLibrary") {
id = "misik.java.library"
implementationClass = "JavaLibraryPlugin"
}

register("buildConfig") {
id = "misik.plugin.build.config"
implementationClass = "BuildConfigPlugin"
}

register("androidTest") {
id = "misik.plugin.android.test"
implementationClass = "AndroidTestPlugin"
}
}
}
35 changes: 35 additions & 0 deletions build-logic/convention/src/main/java/AndroidApplicationPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import com.android.build.api.dsl.ApplicationExtension
import com.nexters.misik.convention.configureAndroidCompose
import com.nexters.misik.convention.configureKotlinAndroid
import com.nexters.misik.convention.extension.getLibrary
import com.nexters.misik.convention.extension.getVersion
import com.nexters.misik.convention.extension.implementation
import com.nexters.misik.convention.extension.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

internal class AndroidApplicationPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.application")
}

extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
configureAndroidCompose(this)
with(defaultConfig) {
targetSdk = libs.getVersion("targetSdk").requiredVersion.toInt()
versionCode = libs.getVersion("versionCode").requiredVersion.toInt()
versionName = libs.getVersion("versionName").requiredVersion
}
}

dependencies {
implementation(libs.getLibrary("timber"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import com.android.build.gradle.LibraryExtension
import com.nexters.misik.convention.configureAndroidCompose
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class AndroidComposeLibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("misik.android.compose.library")
}

extensions.configure<LibraryExtension> {
configureAndroidCompose(this)
}
}
}
}
29 changes: 29 additions & 0 deletions build-logic/convention/src/main/java/AndroidLibraryPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import com.android.build.gradle.LibraryExtension
import com.nexters.misik.convention.configureKotlinAndroid
import com.nexters.misik.convention.configureKotlinCoroutine
import com.nexters.misik.convention.extension.getLibrary
import com.nexters.misik.convention.extension.implementation
import com.nexters.misik.convention.extension.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

class AndroidLibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
}

extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
configureKotlinCoroutine(this)
}

dependencies {
implementation(libs.getLibrary("timber"))
}
}
}
}
15 changes: 15 additions & 0 deletions build-logic/convention/src/main/java/BuildConfigPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import com.android.build.gradle.LibraryExtension
import com.nexters.misik.convention.configureBuildConfig
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class BuildConfigPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
extensions.configure<LibraryExtension> {
configureBuildConfig(this)
}
}
}
}
26 changes: 26 additions & 0 deletions build-logic/convention/src/main/java/HiltPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import com.nexters.misik.convention.extension.getLibrary
import com.nexters.misik.convention.extension.implementation
import com.nexters.misik.convention.extension.ksp
import com.nexters.misik.convention.extension.kspTest
import com.nexters.misik.convention.extension.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies

class HiltPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.devtools.ksp")
apply("dagger.hilt.android.plugin")
}

dependencies {
implementation(libs.getLibrary("hilt.android"))
ksp(libs.getLibrary("hilt.compiler"))
implementation(libs.getLibrary("hilt.testing"))
kspTest(libs.getLibrary("hilt.testing.compiler"))
}
}
}
}
35 changes: 35 additions & 0 deletions build-logic/convention/src/main/java/JavaLibraryPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import com.nexters.misik.convention.Const
import com.nexters.misik.convention.extension.getLibrary
import com.nexters.misik.convention.extension.getVersion
import com.nexters.misik.convention.extension.implementation
import com.nexters.misik.convention.extension.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

class JavaLibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("java-library")
apply("org.jetbrains.kotlin.jvm")
}

extensions.configure<JavaPluginExtension> {
sourceCompatibility = Const.JAVA_VERSION
targetCompatibility = Const.JAVA_VERSION
}

extensions.configure<KotlinProjectExtension> {
jvmToolchain(libs.getVersion("jdkVersion").requiredVersion.toInt())
}

dependencies {
implementation(libs.getLibrary("javax.inject"))
}
}
}
}
13 changes: 13 additions & 0 deletions build-logic/convention/src/main/java/MisikDataPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import org.gradle.api.Plugin
import org.gradle.api.Project

class MisikDataPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("misik.android.library")
apply("misik.android.hilt")
}
}
}
}
Loading