Skip to content

Commit e759943

Browse files
committed
update libs, namespace refactor
1 parent e3bb3fb commit e759943

32 files changed

Lines changed: 451 additions & 225 deletions

File tree

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
*.iml
22
.gradle
3+
.idea
4+
.kotlin
35
/local.properties
4-
/.idea
56
.DS_Store
67
/build
78
/captures
89
.externalNativeBuild
910
.cxx
1011
local.properties
11-
keystore.*
1212
play_config.*
13+
keystore.*
14+
Gemfile.lock
15+
build

app/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,3 @@ dependencies {
1313
implementation(project(":feature:edit"))
1414
implementation(project(":feature:edit-label"))
1515
}
16-
17-
android.namespace = "com.stslex93.notes"

build-logic/dependencies/build.gradle.kts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ plugins {
55
group = "com.stslex93.notes.buildlogic"
66

77
dependencies {
8-
implementation(libs.android.gradlePlugin)
9-
implementation(libs.kotlin.gradlePlugin)
10-
implementation(libs.kotlin.serialization)
8+
compileOnly(libs.android.gradlePlugin)
9+
compileOnly(libs.kotlin.gradlePlugin)
10+
compileOnly(libs.kotlin.serialization)
11+
compileOnly(libs.composeCompiler.gradlePlugin)
12+
compileOnly(libs.android.tools.common)
13+
}
14+
15+
tasks {
16+
validatePlugins {
17+
enableStricterValidation = true
18+
failOnWarning = true
19+
}
1120
}
1221

1322
gradlePlugin {

build-logic/dependencies/src/main/kotlin/AndroidApplicationComposePlugin.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import AppExt.findPluginId
2+
import AppExt.libs
13
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
24
import com.stslex93.notes.configureAndroidCompose
35
import org.gradle.api.Plugin
@@ -8,6 +10,8 @@ class AndroidApplicationComposePlugin : Plugin<Project> {
810
override fun apply(target: Project) {
911
with(target) {
1012
pluginManager.apply("com.android.application")
13+
pluginManager.apply(libs.findPluginId("kotlin"))
14+
pluginManager.apply(libs.findPluginId("composeCompiler"))
1115
val extension = extensions.getByType<BaseAppModuleExtension>()
1216
configureAndroidCompose(extension)
1317
}

build-logic/dependencies/src/main/kotlin/AndroidApplicationPlugin.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import AppExt.APP_PREFIX
2+
import AppExt.findVersionInt
3+
import AppExt.findVersionString
4+
import AppExt.libs
15
import com.android.build.api.dsl.ApplicationExtension
26
import com.stslex93.notes.configureKotlinAndroid
37
import org.gradle.api.Plugin
@@ -20,13 +24,13 @@ class AndroidApplicationPlugin : Plugin<Project> {
2024
extensions.configure<ApplicationExtension> {
2125
configureKotlinAndroid(this)
2226

23-
namespace = "com.stslex93.notes"
27+
namespace = APP_PREFIX
2428

2529
defaultConfig.apply {
26-
applicationId = "com.stslex93.notes"
27-
targetSdk = 34
28-
versionCode = AppVersion.VERSION_CODE
29-
versionName = AppVersion.VERSION_NAME
30+
applicationId = APP_PREFIX
31+
targetSdk = libs.findVersionInt("targetSdk")
32+
versionName = libs.findVersionString("versionName")
33+
versionCode = libs.findVersionInt("versionCode")
3034

3135
signingConfigs {
3236
val keystoreProperties =

build-logic/dependencies/src/main/kotlin/AndroidLibraryComposePlugin.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import AppExt.findPluginId
2+
import AppExt.libs
13
import com.android.build.api.dsl.LibraryExtension
24
import com.stslex93.notes.configureAndroidCompose
35
import org.gradle.api.Plugin
@@ -8,6 +10,8 @@ class AndroidLibraryComposePlugin : Plugin<Project> {
810
override fun apply(target: Project) {
911
with(target) {
1012
pluginManager.apply("com.android.library")
13+
pluginManager.apply(libs.findPluginId("kotlin"))
14+
pluginManager.apply(libs.findPluginId("composeCompiler"))
1115
val extension = extensions.getByType<LibraryExtension>()
1216
configureAndroidCompose(extension)
1317
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import org.gradle.api.Project
2+
import org.gradle.api.artifacts.VersionCatalog
3+
import org.gradle.api.artifacts.VersionCatalogsExtension
4+
import org.gradle.kotlin.dsl.dependencies
5+
import org.gradle.kotlin.dsl.getByType
6+
7+
object AppExt {
8+
9+
const val APP_PREFIX = "com.stslex93.notes"
10+
11+
/**
12+
* Get the version catalog for the project
13+
* */
14+
val Project.libs: VersionCatalog
15+
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")
16+
17+
/**
18+
* Find the version of the library
19+
*/
20+
fun VersionCatalog.findVersionInt(name: String) = findVersionString(name).toInt()
21+
22+
/**
23+
* Find the version of the library
24+
*/
25+
fun VersionCatalog.findVersionString(name: String) = findVersion(name).get().toString()
26+
27+
/**
28+
* Find the plugin id
29+
*/
30+
fun VersionCatalog.findPluginId(alias: String) = findPlugin(alias).get().get().pluginId
31+
32+
/**
33+
* Find the library by alias
34+
*/
35+
fun Project.implementation(vararg alias: String) {
36+
dependencies {
37+
alias.forEach {
38+
add("implementation", libs.findLibrary(it).get())
39+
}
40+
}
41+
}
42+
43+
fun Project.debugImplementation(vararg alias: String) {
44+
dependencies {
45+
alias.forEach {
46+
add("debugImplementation", libs.findLibrary(it).get())
47+
}
48+
}
49+
}
50+
51+
fun Project.implementationPlatform(vararg alias: String) {
52+
dependencies {
53+
alias.forEach {
54+
add(
55+
"debugImplementation",
56+
platform(libs.findLibrary(it).get())
57+
)
58+
}
59+
}
60+
}
61+
62+
/**
63+
* Find the bundle by alias
64+
*/
65+
fun Project.implementationBundle(vararg alias: String) {
66+
dependencies {
67+
alias.forEach {
68+
add("implementation", libs.findBundle(it).get())
69+
}
70+
}
71+
}
72+
73+
/**
74+
* Find the library by alias
75+
*/
76+
fun Project.androidTestImplementation(vararg alias: String) {
77+
dependencies {
78+
alias.forEach {
79+
add("androidTestImplementation", libs.findLibrary(it).get())
80+
}
81+
}
82+
}
83+
84+
/**
85+
* Find the library by alias
86+
*/
87+
fun Project.androidTestImplementationBundle(vararg alias: String) {
88+
dependencies {
89+
alias.forEach {
90+
add("androidTestImplementation", libs.findBundle(it).get())
91+
}
92+
}
93+
}
94+
95+
fun Project.androidTestImplementationPlatform(vararg alias: String) {
96+
dependencies {
97+
alias.forEach {
98+
add(
99+
"androidTestImplementation",
100+
dependencies.platform(libs.findLibrary(it).get())
101+
)
102+
}
103+
}
104+
}
105+
106+
/**
107+
* Find the library by alias
108+
*/
109+
fun Project.testImplementationBundle(vararg alias: String) {
110+
dependencies {
111+
alias.forEach {
112+
add("testImplementation", libs.findBundle(it).get())
113+
}
114+
}
115+
}
116+
117+
/**
118+
* Find the library by alias
119+
*/
120+
fun Project.coreLibraryDesugaring(vararg alias: String) {
121+
dependencies {
122+
alias.forEach {
123+
add("coreLibraryDesugaring", libs.findLibrary(it).get())
124+
}
125+
}
126+
}
127+
128+
/**
129+
* Find the library by alias
130+
*/
131+
fun Project.ksp(vararg alias: String) {
132+
dependencies {
133+
alias.forEach {
134+
add("ksp", libs.findLibrary(it).get())
135+
}
136+
}
137+
}
138+
}

build-logic/dependencies/src/main/kotlin/AppVersion.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.

build-logic/dependencies/src/main/kotlin/com.stslex93.notes/AndroidCompose.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1212
* Configure Compose-specific options
1313
*/
1414
internal fun Project.configureAndroidCompose(
15-
commonExtension: CommonExtension<*, *, *, *, *>,
15+
commonExtension: CommonExtension<*, *, *, *, *, *>,
1616
) {
1717
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
1818

1919
commonExtension.apply {
2020

2121
buildFeatures.compose = true
22-
composeOptions.kotlinCompilerExtensionVersion = libs
23-
.findVersion("composeCompiler")
24-
.get()
25-
.toString()
2622

2723
dependencies {
2824
val composeBom = libs.findLibrary("androidx-compose-bom").get()
@@ -56,8 +52,8 @@ internal fun Project.configureAndroidCompose(
5652
}
5753

5854
tasks.withType<KotlinCompile>().configureEach {
59-
kotlinOptions {
60-
freeCompilerArgs = freeCompilerArgs //+ buildComposeMetricsParameters()
55+
compilerOptions {
56+
// freeCompilerArgs.add(buildComposeMetricsParameters())
6157
}
6258
}
6359
}
Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
package com.stslex93.notes
22

3+
import AppExt.APP_PREFIX
4+
import AppExt.findVersionInt
5+
import AppExt.libs
36
import com.android.build.api.dsl.CommonExtension
7+
import com.android.build.gradle.AppExtension
48
import org.gradle.api.JavaVersion
59
import org.gradle.api.Project
610
import org.gradle.api.artifacts.VersionCatalogsExtension
711
import org.gradle.kotlin.dsl.dependencies
812
import org.gradle.kotlin.dsl.getByType
913
import org.gradle.kotlin.dsl.provideDelegate
1014
import org.gradle.kotlin.dsl.withType
15+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1116
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1217

1318
/**
1419
* Configure base Kotlin with Android options
1520
*/
1621
internal fun Project.configureKotlinAndroid(
17-
commonExtension: CommonExtension<*, *, *, *, *>,
18-
) {
19-
commonExtension.apply {
22+
commonExtension: CommonExtension<*, *, *, *, *, *>,
23+
): Unit = with(commonExtension) {
2024

21-
compileSdk = 34
25+
compileSdk = libs.findVersionInt("compileSdk")
2226

23-
defaultConfig {
24-
minSdk = 28
25-
buildFeatures.buildConfig = true
26-
}
27+
namespace = getNameSpace(commonExtension)
2728

28-
compileOptions {
29-
// Up to Java 11 APIs are available through desugaring
30-
// https://developer.android.com/studio/write/java11-minimal-support-table
31-
sourceCompatibility = JavaVersion.VERSION_11
32-
targetCompatibility = JavaVersion.VERSION_11
33-
isCoreLibraryDesugaringEnabled = true
34-
}
29+
defaultConfig {
30+
minSdk = libs.findVersionInt("minSdk")
31+
buildFeatures.buildConfig = true
32+
}
33+
34+
compileOptions {
35+
// Up to Java 11 APIs are available through desugaring
36+
// https://developer.android.com/studio/write/java11-minimal-support-table
37+
sourceCompatibility = JavaVersion.VERSION_17
38+
targetCompatibility = JavaVersion.VERSION_17
39+
isCoreLibraryDesugaringEnabled = true
3540
}
3641

3742
configureKotlin()
@@ -61,22 +66,29 @@ internal fun Project.configureKotlinAndroid(
6166
}
6267
}
6368

64-
/**
65-
* Configure base Kotlin options
66-
*/
69+
private fun Project.getNameSpace(
70+
commonExtension: CommonExtension<*, *, *, *, *, *>,
71+
): String {
72+
val isApp = commonExtension is AppExtension
73+
val dropValue = if (isApp) 2 else 1
74+
val moduleName = path.split(":")
75+
.drop(dropValue)
76+
.joinToString(".")
77+
.replace("-", "_")
78+
return if (moduleName.isNotEmpty()) "$APP_PREFIX.$moduleName" else APP_PREFIX
79+
}
80+
6781
private fun Project.configureKotlin() {
6882
// Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947
6983
tasks.withType<KotlinCompile>().configureEach {
70-
kotlinOptions {
84+
compilerOptions {
7185
// Set JVM target to 11
72-
jvmTarget = JavaVersion.VERSION_11.toString()
86+
jvmTarget.set(JvmTarget.JVM_17)
7387
// Treat all Kotlin warnings as errors (disabled by default)
7488
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties
7589
val warningsAsErrors: String? by project
76-
allWarningsAsErrors = warningsAsErrors.toBoolean()
77-
freeCompilerArgs = freeCompilerArgs + listOf(
78-
"-opt-in=kotlin.RequiresOptIn",
79-
)
90+
allWarningsAsErrors.set(warningsAsErrors?.toBoolean() ?: false)
91+
freeCompilerArgs.addAll("-opt-in=kotlin.RequiresOptIn", "-Xcontext-parameters")
8092
}
8193
}
8294
}

0 commit comments

Comments
 (0)