Skip to content

Commit

Permalink
Merge pull request #2 from Team-Shaka/feat/#1-convention
Browse files Browse the repository at this point in the history
Feat/#1 convention
  • Loading branch information
DongChyeon authored Feb 26, 2024
2 parents 217cebc + d8bb222 commit fd6ea4d
Show file tree
Hide file tree
Showing 63 changed files with 919 additions and 76 deletions.
72 changes: 11 additions & 61 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,70 +1,20 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
import store.newsbriefing.app.buildlogic.config.Config

plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.briefing.android.application)
alias(libs.plugins.briefing.android.application.compose)
}

android {
namespace = "com.dev.briefing"
compileSdk = 34

defaultConfig {
applicationId = "com.dev.briefing"
minSdk = 28
targetSdk = 34
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_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
namespace = Config.android.nameSpace
}

dependencies {
implementation(projects.core.designsystem)

implementation(libs.core.ktx)
implementation(libs.lifecycle.runtime.ktx)
implementation(libs.activity.compose)
implementation(platform(libs.compose.bom))
implementation(libs.ui)
implementation(libs.ui.graphics)
implementation(libs.ui.tooling.preview)
implementation(libs.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
androidTestImplementation(platform(libs.compose.bom))
androidTestImplementation(libs.ui.test.junit4)
debugImplementation(libs.ui.tooling)
debugImplementation(libs.ui.test.manifest)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.ui.tooling.preview)
}
3 changes: 1 addition & 2 deletions app/src/main/java/com/dev/briefing/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.dev.briefing.ui.theme.BriefingTheme
import store.newsbriefing.app.core.designsystem.theme.BriefingTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BriefingTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
Expand Down
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 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "store.newsbriefing.app.buildlogic"

plugins {
`kotlin-dsl`
}

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.android.tools.common)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.ksp.gradlePlugin)
}

gradlePlugin {
plugins {
register("androidApplicationCompose") {
id = "store.newsbriefing.app.buildlogic.plugin.android.application.compose"
implementationClass =
"store.newsbriefing.app.buildlogic.plugin.AndroidApplicationComposeConventionPlugin"
}
register("androidApplication") {
id = "store.newsbriefing.app.buildlogic.plugin.android.application"
implementationClass =
"store.newsbriefing.app.buildlogic.plugin.AndroidApplicationConventionPlugin"
}
register("androidLibrary") {
id = "store.newsbriefing.app.buildlogic.plugin.android.library"
implementationClass =
"store.newsbriefing.app.buildlogic.plugin.AndroidLibraryConventionPlugin"
}
register("androidLibraryCompose") {
id = "store.newsbriefing.app.buildlogic.plugin.android.library.compose"
implementationClass =
"store.newsbriefing.app.buildlogic.plugin.AndroidLibraryComposeConventionPlugin"
}
register("androidHilt") {
id = "store.newsbriefing.app.buildlogic.plugin.android.hilt"
implementationClass =
"store.newsbriefing.app.buildlogic.plugin.AndroidHiltConventionPlugin"
}
register("jvmLibrary") {
id = "store.newsbriefing.app.buildlogic.plugin.jvm.library"
implementationClass =
"store.newsbriefing.app.buildlogic.plugin.JvmLibraryConventionPlugin"
}
register("androidFeature") {
id = "store.newsbriefing.app.buildlogic.plugin.android.feature"
implementationClass =
"store.newsbriefing.app.buildlogic.plugin.AndroidFeatureConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package store.newsbriefing.app.buildlogic.config

import org.gradle.api.JavaVersion

object Config {
val android = AndroidConfig(
minSdkVersion = 28,
targetSdkVersion = 34,
compileSdkVersion = 34,
applicationId = "com.dev.briefing",
versionCode = 1,
versionName = "1.0",
nameSpace = "com.dev.briefing"
)
val jvm = JvmConfig(
javaVersion = JavaVersion.VERSION_18,
kotlinJvm = JavaVersion.VERSION_18.toString(),
freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn")
)
}
data class AndroidConfig(
val minSdkVersion : Int,
val targetSdkVersion : Int,
val compileSdkVersion : Int,
val applicationId : String,
val versionCode : Int,
val versionName : String,
val nameSpace: String
)
data class JvmConfig(
val javaVersion : JavaVersion,
val kotlinJvm : String,
val freeCompilerArgs : List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package store.newsbriefing.app.buildlogic.extension

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies

internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *>,
) {
commonExtension.apply {
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.findVersion("androidxComposeCompiler").get().toString()
}

dependencies {
val bom = libs.findLibrary("compose-bom").get()
add("implementation", platform(bom))
add("implementation", platform(bom))

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package store.newsbriefing.app.buildlogic.extension

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
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.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import store.newsbriefing.app.buildlogic.config.Config


internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
) {
// android scope
commonExtension.apply {
compileSdk = Config.android.compileSdkVersion

defaultConfig {
minSdk = Config.android.minSdkVersion
}

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

configureKotlin()

dependencies {
}
}

internal fun Project.configureKotlinJvm() {
extensions.configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_18
targetCompatibility = JavaVersion.VERSION_18
}
configureKotlin()
}

private fun Project.configureKotlin() {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_18.toString()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package store.newsbriefing.app.buildlogic.extension

import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

val Project.libs
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package store.newsbriefing.app.buildlogic.plugin

import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
import store.newsbriefing.app.buildlogic.extension.configureAndroidCompose

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

val extension = extensions.getByType<ApplicationExtension>()
configureAndroidCompose(extension)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package store.newsbriefing.app.buildlogic.plugin

import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import store.newsbriefing.app.buildlogic.config.Config
import store.newsbriefing.app.buildlogic.extension.configureKotlinAndroid

class AndroidApplicationConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.application")
apply("org.jetbrains.kotlin.android")
}
// android
extensions.configure<ApplicationExtension> {
// default config
defaultConfig.apply {
targetSdk = Config.android.targetSdkVersion
applicationId = Config.android.applicationId
versionCode = Config.android.versionCode
versionName = Config.android.versionName
}
configureKotlinAndroid(this)

packaging {
resources {
excludes.add("/META-INF/AL2.0")
excludes.add("/META-INF/LGPL2.1")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package store.newsbriefing.app.buildlogic.plugin

import com.android.build.gradle.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import store.newsbriefing.app.buildlogic.extension.libs

class AndroidFeatureConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply {
apply("store.newsbriefing.app.buildlogic.plugin.android.library")
apply("store.newsbriefing.app.buildlogic.plugin.android.hilt")
}

dependencies {
add("implementation", project(":core:ui"))
add("implementation", project(":core:designsystem"))

// add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
// add("implementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
// add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package store.newsbriefing.app.buildlogic.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import store.newsbriefing.app.buildlogic.extension.libs

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

dependencies {
"implementation"(libs.findLibrary("hilt.android").get())
"ksp"(libs.findLibrary("hilt.compiler").get())
}
}
}
}
Loading

0 comments on commit fd6ea4d

Please sign in to comment.