Skip to content

Commit

Permalink
chore: Add build logic module
Browse files Browse the repository at this point in the history
  • Loading branch information
hushenghao committed Nov 26, 2023
1 parent da9ddae commit 6880c01
Show file tree
Hide file tree
Showing 34 changed files with 256 additions and 387 deletions.
13 changes: 12 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 3 additions & 26 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
@file:Suppress("UnstableApiUsage")

import Versions.gitHash
import Versions.keyprops

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
kotlin("kapt")
alias(libs.plugins.hilt.android)
}

apply(from = "../buildSrc/tasks.gradle.kts")

kapt {
correctErrorTypes = true
id("easter.egg.app")
}

android {
compileSdk = Versions.COMPILE_SDK
buildToolsVersion = Versions.BUILD_TOOLS
namespace = "com.dede.android_eggs"

defaultConfig {
applicationId = "com.dede.android_eggs"
minSdk = Versions.MIN_SDK
targetSdk = Versions.TARGET_SDK
versionCode = 35
versionName = "2.2.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -44,10 +29,6 @@ android {
buildConfigField("String", "GIT_HASH", "\"${gitHash}\"")
// Language configuration only
buildConfigField("int", "LANGUAGE_RES", resourceConfigurations.size.toString())

vectorDrawables {
useSupportLibrary = true
}
}

buildFeatures {
Expand All @@ -72,10 +53,10 @@ android {

buildTypes {
val config = signingConfigs.findByName("release") ?: signingConfigs.getByName("debug")
getByName("debug") {
debug {
signingConfig = config
}
getByName("release") {
release {
isShrinkResources = true
isMinifyEnabled = true
proguardFiles(
Expand All @@ -92,7 +73,6 @@ android {

lint {
disable += listOf("NotifyDataSetChanged", "UsingMaterialAndMaterial3Libraries")
fatal += listOf("NewApi", "InlineApi")
}

packaging {
Expand All @@ -116,8 +96,6 @@ dependencies {
implementation(libs.androidx.window)
implementation(libs.google.material)
implementation(libs.androidx.startup)
implementation(libs.hilt.android)
kapt(libs.hilt.compiler)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.compose)
implementation(platform(libs.androidx.compose.bom))
Expand All @@ -138,7 +116,6 @@ dependencies {
implementation(libs.blurhash.android)
debugImplementation(libs.squareup.leakcanary)

implementation(project(":basic"))
implementation(project(":eggs:U"))
implementation(project(":eggs:T"))
implementation(project(":eggs:S"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class ViscousFluidInterpolator : Interpolator {
// account for very small floating-point error
private var VISCOUS_FLUID_OFFSET = 1.0f - VISCOUS_FLUID_NORMALIZE * viscousFluid(1.0f)

private fun viscousFluid(x: Float): Float {
var x = x
private fun viscousFluid(ix: Float): Float {
var x = ix
x *= VISCOUS_FLUID_SCALE
if (x < 1.0f) {
x -= 1.0f - exp(-x.toDouble()).toFloat()
Expand Down
20 changes: 1 addition & 19 deletions basic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
id("easter.egg.basic.library")
}

android {
compileSdk = Versions.COMPILE_SDK
buildToolsVersion = Versions.BUILD_TOOLS
namespace = "com.dede.basic"
defaultConfig {
minSdk = Versions.MIN_SDK
}

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

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/.gitignore → build-logic/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.gradle
build
build
33 changes: 33 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
`kotlin-dsl`
}

group = "easter.eggs.build-logic"

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

dependencies {
implementation(libs.android.tools.sdk.common)
compileOnly(libs.android.gradle.plugin)
compileOnly(libs.kotlin.gradle.plugin)
}

gradlePlugin {
plugins {
register("easterEggBasicLibrary") {
id = "easter.egg.basic.library"
implementationClass = "EasterEggBasicLibrary"
}
register("easterEggLibrary") {
id = "easter.egg.library"
implementationClass = "EasterEggLibrary"
}
register("easterEggApp") {
id = "easter.egg.app"
implementationClass = "EasterEggApp"
}
}
}
3 changes: 3 additions & 0 deletions build-logic/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
13 changes: 13 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
44 changes: 44 additions & 0 deletions build-logic/src/main/kotlin/Dls.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import com.android.build.gradle.BaseExtension
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val Project.catalog: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")

fun Project.configureKotlin() {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = Versions.JAVA_VERSION.toString()
}
}
}

fun <T : BaseExtension> Project.configureAndroid(configure: Action<T>? = null) {
extensions.configure<BaseExtension>("android") {
compileSdkVersion(Versions.COMPILE_SDK)
buildToolsVersion = Versions.BUILD_TOOLS

defaultConfig {
minSdk = Versions.MIN_SDK

vectorDrawables {
useSupportLibrary = true
}
}

compileOptions {
sourceCompatibility = Versions.JAVA_VERSION
targetCompatibility = Versions.JAVA_VERSION
}

configureKotlin()

@Suppress("UNCHECKED_CAST")
configure?.execute(this as T)
}
}
35 changes: 35 additions & 0 deletions build-logic/src/main/kotlin/EasterEggApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.project

class EasterEggApp : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
pluginManager.apply {
apply("com.android.application")
apply("com.google.dagger.hilt.android")
apply("org.jetbrains.kotlin.android")
apply("kotlin-kapt")
}

dependencies {
"implementation"(project(path = ":basic"))
"implementation"(catalog.findLibrary("hilt.android").get())
"kapt"(catalog.findLibrary("hilt.compiler").get())
}

configureAndroid<BaseAppModuleExtension> {
defaultConfig {
targetSdk = Versions.TARGET_SDK
}

lint {
fatal += listOf("NewApi", "InlineApi")
}
}
}
}
}
39 changes: 39 additions & 0 deletions build-logic/src/main/kotlin/EasterEggBasicLibrary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project

open class EasterEggBasicLibrary : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
pluginManager.apply {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
}

configureAndroid<LibraryExtension> {
defaultConfig {
consumerProguardFiles("consumer-rules.pro")
}

lint {
fatal += listOf("NewApi", "InlineApi")
}

buildFeatures {
buildConfig = false
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
}
}
}
34 changes: 34 additions & 0 deletions build-logic/src/main/kotlin/EasterEggLibrary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.project

class EasterEggLibrary : EasterEggBasicLibrary() {

override fun apply(target: Project) {
super.apply(target)
with(target) {
pluginManager.apply {
apply("com.google.dagger.hilt.android")
apply("kotlin-kapt")
}

dependencies {
"implementation"(project(path = ":basic"))
"implementation"(catalog.findLibrary("hilt.android").get())
"kapt"(catalog.findLibrary("hilt.compiler").get())
}

configureAndroid<LibraryExtension> {
val key = name.substring(0, 1).lowercase()
namespace = "com.android_$key.egg"
resourcePrefix("${key}_")

lint {
baseline = project.file("lint-baseline.xml")
}
}
}
}

}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dede.easter_eggs
package com.dede.easter.eggs

import com.android.ide.common.vectordrawable.Svg2Vector
import org.gradle.api.DefaultTask
Expand All @@ -9,7 +9,6 @@ import java.io.File
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.net.http.HttpResponse.BodyHandlers

/**
Expand Down
Loading

0 comments on commit 6880c01

Please sign in to comment.