Skip to content

Commit

Permalink
Merge pull request #1 from Team-HMH/setting/build_logic
Browse files Browse the repository at this point in the history
[setting]: build-logic 추가 작업
  • Loading branch information
kez-lab authored Dec 27, 2023
2 parents 5d04e0c + 89dde0f commit c06bc48
Show file tree
Hide file tree
Showing 21 changed files with 371 additions and 9 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import java.util.Properties

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
hmh("application")
hmh("compose")
hmh("test")
}

android {
Expand Down Expand Up @@ -54,6 +57,7 @@ dependencies {
implementation(libs.core.ktx)
implementation(libs.lifecycle)
implementation(libs.activity.compose)
implementation(libs.retrofit)
implementation(platform(libs.compose.bom))

//appcompat implementation
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.HMHAndroid" parent="Theme.AppCompat.Light.NoActionBar" />
</resources>
54 changes: 54 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
`kotlin-dsl`
}

group = "com.hmh.hamyeonham.buildlogic"

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


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

gradlePlugin {
plugins {
create("android-application") {
id = "com.hmh.hamyeonham.application"
implementationClass = "com.hmh.hamyeonham.plugin.AndroidApplicationPlugin"
}
create("android-feature") {
id = "com.hmh.hamyeonham.feature"
implementationClass = "com.hmh.hamyeonham.plugin.AndroidFeaturePlugin"
}
create("android-kotlin") {
id = "com.hmh.hamyeonham.kotlin"
implementationClass = "com.hmh.hamyeonham.plugin.AndroidKotlinPlugin"
}
create("android-hilt") {
id = "com.hmh.hamyeonham.hilt"
implementationClass = "com.hmh.hamyeonham.plugin.AndroidHiltPlugin"
}
create("kotlin-serialization") {
id = "com.hmh.hamyeonham.serialization"
implementationClass = "com.hmh.hamyeonham.plugin.KotlinSerializationPlugin"
}
create("junit5") {
id = "com.hmh.hamyeonham.junit5"
implementationClass = "com.hmh.hamyeonham.plugin.JUnit5Plugin"
}
create("android-test") {
id = "com.hmh.hamyeonham.test"
implementationClass = "com.hmh.hamyeonham.plugin.AndroidTestPlugin"
}
create("compose") {
id = "com.hmh.hamyeonham.compose"
implementationClass = "com.hmh.hamyeonham.plugin.ComposePlugin"
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hmh.hamyeonham.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project

class AndroidApplicationPlugin: Plugin<Project> {
override fun apply(target: Project) = with(target) {
plugins.apply("com.android.application")
configureAndroidCommonPlugin()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hmh.hamyeonham.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

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

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
"implementation"(libs.findLibrary("hilt").get())
"ksp"(libs.findLibrary("hilt.compiler").get())
"testImplementation"(libs.findLibrary("hilt.testing").get())
"kspTest"(libs.findLibrary("hilt.testing.compiler").get())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.hmh.hamyeonham.plugin

import com.android.build.gradle.BaseExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions

class AndroidKotlinPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
with(plugins) {
apply("kotlin-android")
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
extensions.getByType<BaseExtension>().apply {
setCompileSdkVersion(libs.findVersion("compileSdk").get().requiredVersion.toInt())

defaultConfig {
minSdk = libs.findVersion("minSdk").get().requiredVersion.toInt()
targetSdk = libs.findVersion("targetSdk").get().requiredVersion.toInt()
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

(this as ExtensionAware).configure<KotlinJvmOptions> {
jvmTarget = "17"
}
}

dependencies {
"coreLibraryDesugaring"(libs.findLibrary("desugarLibs").get())
"implementation"(libs.findLibrary("kotlin").get())
"implementation"(libs.findLibrary("kotlin.coroutines").get())
"implementation"(libs.findLibrary("kotlin.datetime").get())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hmh.hamyeonham.plugin

import com.android.build.gradle.BaseExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

class AndroidTestPlugin: Plugin<Project> {
override fun apply(target: Project): Unit = with(target) {
apply<JUnit5Plugin>()
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

extensions.getByType<BaseExtension>().apply {
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
}

testOptions {
unitTests {
isIncludeAndroidResources = true
}
}

packagingOptions {
resources.excludes.add("META-INF/LICENSE*")
}
}

dependencies {
"testImplementation"(libs.findLibrary("junit").get())
"debugImplementation"(libs.findLibrary("truth").get())
"testImplementation"(libs.findLibrary("robolectric").get())
"androidTestImplementation"(libs.findBundle("androidx.android.test").get())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.hmh.hamyeonham.plugin

import com.android.build.gradle.BaseExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import java.util.Properties

internal fun Project.configureAndroidCommonPlugin() {
val properties = Properties().apply {
load(rootProject.file("local.properties").inputStream())
}

apply<AndroidKotlinPlugin>()
apply<KotlinSerializationPlugin>()
with(plugins) {
apply("kotlin-parcelize")
}
apply<AndroidHiltPlugin>()

extensions.getByType<BaseExtension>().apply {
defaultConfig {}
buildFeatures.apply {
viewBinding = true
buildConfig = true
}
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
"implementation"(libs.findLibrary("core.ktx").get())
"implementation"(libs.findLibrary("appcompat").get())
"implementation"(libs.findBundle("lifecycle").get())
"implementation"(libs.findLibrary("material").get())
"implementation"(libs.findLibrary("timber").get())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hmh.hamyeonham.plugin

import com.android.build.gradle.BaseExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

class ComposePlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
extensions.getByType<BaseExtension>().apply {
buildFeatures.apply {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.findVersion("compose.compiler").get().requiredVersion
}
}

dependencies {
"implementation"(platform(libs.findLibrary("compose.bom").get()))
"implementation"(libs.findBundle("compose").get())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hmh.hamyeonham.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

class JUnit5Plugin : Plugin<Project> {
override fun apply(target: Project): Unit = with(target) {
with(plugins) {
apply("de.mannodermaus.android-junit5")
}
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

dependencies {
"testImplementation"(libs.findBundle("junit5").get())
"androidTestImplementation"(libs.findLibrary("junit5").get())
"androidTestImplementation"(libs.findLibrary("junit5.params").get())
"androidTestImplementation"(libs.findLibrary("junit5.android.test.core").get())
"androidTestRuntimeOnly"(libs.findLibrary("junit5.android.test.runner").get())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hmh.hamyeonham.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

class KotlinSerializationPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
with(plugins) {
apply("org.jetbrains.kotlin.plugin.serialization")
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
"implementation"(libs.findLibrary("kotlin.serialization.json").get())
}
}
}
4 changes: 4 additions & 0 deletions build-logic/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Gradle properties are not passed to included builds https://github.com/gradle/gradle/issues/2534
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
6 changes: 6 additions & 0 deletions build-logic/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Fri Jan 13 12:46:38 KST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 15 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
include(":convention")

35 changes: 31 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}

dependencies {
classpath(libs.kotlin.gradleplugin)
classpath(libs.hilt.plugin)
classpath(libs.agp)
classpath(libs.ktlint)
classpath(libs.oss.plugin)
}
}

plugins {
id("com.android.application") version "8.2.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.android.library") version "8.2.0" apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.dagger.hilt) apply false
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.junit5) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.app.distribution) apply false
alias(libs.plugins.crashlytics) apply false
}

tasks.register("clean", Delete::class) {
delete(rootProject.layout.buildDirectory)
}
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
}
Loading

0 comments on commit c06bc48

Please sign in to comment.