diff --git a/core/src/main/kotlin/com/mitteloupe/cag/core/Generator.kt b/core/src/main/kotlin/com/mitteloupe/cag/core/Generator.kt index 77696ab..baa9456 100644 --- a/core/src/main/kotlin/com/mitteloupe/cag/core/Generator.kt +++ b/core/src/main/kotlin/com/mitteloupe/cag/core/Generator.kt @@ -72,20 +72,13 @@ class Generator( val featureNameLowerCase = request.featureName.lowercase() val dependencyConfiguration = DependencyConfiguration( - versions = - buildList { - addAll(VersionCatalogConstants.KOTLIN_VERSIONS + VersionCatalogConstants.ANDROID_VERSIONS) - if (request.enableCompose) { - addAll(VersionCatalogConstants.COMPOSE_VERSIONS) - } - if (request.enableKtlint) { - addAll(VersionCatalogConstants.KTLINT_VERSIONS) - } - if (request.enableDetekt) { - addAll(VersionCatalogConstants.DETEKT_VERSIONS) - } + versions = VersionCatalogConstants.ANDROID_VERSIONS, + libraries = + if (request.enableCompose) { + LibraryConstants.COMPOSE_LIBRARIES + } else { + emptyList() }, - libraries = if (request.enableCompose) LibraryConstants.COMPOSE_LIBRARIES else emptyList(), plugins = buildList { addAll(PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS) @@ -270,7 +263,7 @@ class Generator( val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.KOTLIN_VERSIONS + VersionCatalogConstants.ANDROID_VERSIONS, + versions = VersionCatalogConstants.ANDROID_VERSIONS, libraries = emptyList(), plugins = PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS ) @@ -421,17 +414,6 @@ class Generator( throw GenerationException("Failed to create project directory.") } - val versions = - buildList { - addAll( - VersionCatalogConstants.KOTLIN_VERSIONS + - VersionCatalogConstants.ANDROID_VERSIONS + - VersionCatalogConstants.TESTING_VERSIONS - ) - if (request.enableCompose) { - addAll(VersionCatalogConstants.COMPOSE_VERSIONS) - } - } val libraries = LibraryConstants.CORE_ANDROID_LIBRARIES + LibraryConstants.TESTING_LIBRARIES + if (request.enableCompose) { @@ -454,7 +436,7 @@ class Generator( } val dependencyConfiguration = DependencyConfiguration( - versions = versions, + versions = VersionCatalogConstants.ANDROID_VERSIONS, libraries = libraries, plugins = plugins ) diff --git a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/ArchitectureModulesContentGenerator.kt b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/ArchitectureModulesContentGenerator.kt index a6b64dd..7ad1ad1 100644 --- a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/ArchitectureModulesContentGenerator.kt +++ b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/ArchitectureModulesContentGenerator.kt @@ -53,19 +53,6 @@ class ArchitectureModulesContentGenerator( throw GenerationException("Failed to create directories for architecture package '$architecturePackageName'.") } - val versions = - buildList { - addAll(VersionCatalogConstants.KOTLIN_VERSIONS + VersionCatalogConstants.ANDROID_VERSIONS) - if (enableCompose) { - addAll(VersionCatalogConstants.COMPOSE_VERSIONS) - } - if (enableKtlint) { - addAll(VersionCatalogConstants.KTLINT_VERSIONS) - } - if (enableDetekt) { - addAll(VersionCatalogConstants.DETEKT_VERSIONS) - } - } val libraries = LibraryConstants.CORE_ANDROID_LIBRARIES + if (enableCompose) { @@ -94,7 +81,7 @@ class ArchitectureModulesContentGenerator( } val dependencyConfiguration = DependencyConfiguration( - versions = versions, + versions = VersionCatalogConstants.ANDROID_VERSIONS, libraries = libraries, plugins = plugins ) diff --git a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/CoroutineModuleContentGenerator.kt b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/CoroutineModuleContentGenerator.kt index 09ebf7d..9ed49d9 100644 --- a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/CoroutineModuleContentGenerator.kt +++ b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/architecture/CoroutineModuleContentGenerator.kt @@ -36,8 +36,8 @@ class CoroutineModuleContentGenerator( val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.KOTLIN_VERSIONS + VersionCatalogConstants.ANDROID_VERSIONS, - libraries = LibraryConstants.CORE_ANDROID_LIBRARIES, + versions = VersionCatalogConstants.ANDROID_VERSIONS, + libraries = listOf(LibraryConstants.KOTLINX_COROUTINES_CORE), plugins = PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS ) catalogUpdater.updateVersionCatalogIfPresent( diff --git a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/DependencyConfiguration.kt b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/DependencyConfiguration.kt index 42aa8bb..3a54208 100644 --- a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/DependencyConfiguration.kt +++ b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/DependencyConfiguration.kt @@ -3,11 +3,39 @@ package com.mitteloupe.cag.core.generation.versioncatalog import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.LibraryRequirement import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.PluginRequirement import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.VersionRequirement +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_ACTIVITY_COMPOSE_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_APPCOMPAT_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_CONSTRAINT_LAYOUT_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_CORE_KTX_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_FRAGMENT_KTX_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_LIFECYCLE_RUNTIME_KTX_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_NAVIGATION_FRAGMENT_KTX_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROIDX_RECYCLER_VIEW_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.ANDROID_GRADLE_PLUGIN_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.COMPOSE_BOM_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.COMPOSE_NAVIGATION_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.DETEKT_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.JUNIT4_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.KOTLINX_COROUTINES_CORE_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.KOTLIN_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.KSP_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.KTLINT_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.KTOR_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.MATERIAL_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.OKHTTP3_LOGGING_INTERCEPTOR_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.OKHTTP3_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.RETROFIT_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.TEST_ANDROIDX_ESPRESSO_CORE_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.TEST_ANDROIDX_JUNIT_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.TEST_ANDROIDX_RULES_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.TEST_ANDROID_HILT_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.TEST_ANDROID_MOCKWEBSERVER_VERSION +import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants.TEST_ANDROID_UI_AUTOMATOR_VERSION data class DependencyConfiguration( - val versions: List = emptyList(), - val libraries: List = emptyList(), - val plugins: List = emptyList() + val versions: List, + val libraries: List, + val plugins: List ) object VersionCatalogConstants { @@ -20,7 +48,6 @@ object VersionCatalogConstants { val COMPOSE_BOM_VERSION = VersionRequirement(key = "composeBom", version = "2025.08.01") val COMPOSE_NAVIGATION_VERSION = VersionRequirement(key = "composeNavigation", version = "2.9.3") - val COMPOSE_COMPILER_VERSION = VersionRequirement(key = "composeCompiler", version = "1.5.8") val JUNIT4_VERSION = VersionRequirement(key = "junit4", version = "4.13.2") val KSP_VERSION = VersionRequirement(key = "ksp", version = "2.2.10-2.0.2") @@ -28,11 +55,30 @@ object VersionCatalogConstants { val KTLINT_VERSION = VersionRequirement(key = "ktlint", version = "13.1.0") val DETEKT_VERSION = VersionRequirement(key = "detekt", version = "1.23.6") - val KOTLIN_VERSIONS = - listOf( - KOTLIN_VERSION, - KSP_VERSION - ) + val ANDROIDX_CORE_KTX_VERSION = VersionRequirement(key = "androidxCoreKtx", version = "1.12.0") + val ANDROIDX_LIFECYCLE_RUNTIME_KTX_VERSION = VersionRequirement(key = "androidxLifecycleRuntimeKtx", version = "2.7.0") + val KOTLINX_COROUTINES_CORE_VERSION = VersionRequirement(key = "kotlinxCoroutinesCore", version = "1.7.3") + val MATERIAL_VERSION = VersionRequirement(key = "material", version = "1.11.0") + val OKHTTP3_VERSION = VersionRequirement(key = "okhttp3", version = "4.12.0") + val ANDROIDX_APPCOMPAT_VERSION = VersionRequirement(key = "androidxAppcompat", version = "1.6.1") + + val ANDROIDX_RECYCLER_VIEW_VERSION = VersionRequirement(key = "androidxRecyclerView", version = "1.3.2") + val ANDROIDX_FRAGMENT_KTX_VERSION = VersionRequirement(key = "androidxFragmentKtx", version = "1.6.2") + val ANDROIDX_NAVIGATION_FRAGMENT_KTX_VERSION = VersionRequirement(key = "androidxNavigationFragmentKtx", version = "2.7.6") + val ANDROIDX_CONSTRAINT_LAYOUT_VERSION = VersionRequirement(key = "androidxConstraintLayout", version = "2.1.4") + + val ANDROIDX_ACTIVITY_COMPOSE_VERSION = VersionRequirement(key = "androidxActivityCompose", version = "1.8.2") + + val KTOR_VERSION = VersionRequirement(key = "ktor", version = "3.0.3") + val RETROFIT_VERSION = VersionRequirement(key = "retrofit", version = "2.11.0") + val OKHTTP3_LOGGING_INTERCEPTOR_VERSION = VersionRequirement(key = "okhttp3LoggingInterceptor", version = "4.12.0") + + val TEST_ANDROIDX_JUNIT_VERSION = VersionRequirement(key = "androidxJunit", version = "1.1.5") + val TEST_ANDROIDX_ESPRESSO_CORE_VERSION = VersionRequirement(key = "androidxEspressoCore", version = "3.5.1") + val TEST_ANDROID_HILT_VERSION = VersionRequirement(key = "androidHilt", version = "2.48") + val TEST_ANDROID_UI_AUTOMATOR_VERSION = VersionRequirement(key = "androidxUiautomator", version = "2.2.0") + val TEST_ANDROID_MOCKWEBSERVER_VERSION = VersionRequirement(key = "mockwebserver", version = "4.12.0") + val TEST_ANDROIDX_RULES_VERSION = VersionRequirement(key = "androidxTestRules", version = "1.5.0") val ANDROID_VERSIONS = listOf( @@ -41,19 +87,6 @@ object VersionCatalogConstants { TARGET_SDK_VERSION, ANDROID_GRADLE_PLUGIN_VERSION ) - - val COMPOSE_VERSIONS = - listOf( - COMPOSE_BOM_VERSION, - COMPOSE_NAVIGATION_VERSION, - COMPOSE_COMPILER_VERSION - ) - - val TESTING_VERSIONS = listOf(JUNIT4_VERSION) - - val KTLINT_VERSIONS = listOf(KTLINT_VERSION) - - val DETEKT_VERSIONS = listOf(DETEKT_VERSION) } object LibraryConstants { @@ -61,28 +94,28 @@ object LibraryConstants { LibraryRequirement( key = "androidx-core-ktx", module = "androidx.core:core-ktx", - versionLiteral = "1.12.0" + version = ANDROIDX_CORE_KTX_VERSION ) val ANDROIDX_LIFECYCLE_RUNTIME_KTX = LibraryRequirement( key = "androidx-lifecycle-runtime-ktx", module = "androidx.lifecycle:lifecycle-runtime-ktx", - versionLiteral = "2.7.0" + version = ANDROIDX_LIFECYCLE_RUNTIME_KTX_VERSION ) val KOTLINX_COROUTINES_CORE = LibraryRequirement( key = "kotlinx-coroutines-core", module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", - versionLiteral = "1.7.3" + version = KOTLINX_COROUTINES_CORE_VERSION ) val COMPOSE_BOM = LibraryRequirement( key = "compose-bom", module = "androidx.compose:compose-bom", - versionRefKey = "composeBom" + version = COMPOSE_BOM_VERSION ) val COMPOSE_UI = @@ -113,56 +146,56 @@ object LibraryConstants { LibraryRequirement( key = "compose-navigation", module = "androidx.navigation:navigation-compose", - versionRefKey = "composeNavigation" + version = COMPOSE_NAVIGATION_VERSION ) val TEST_JUNIT = LibraryRequirement( key = "test-junit", module = "junit:junit", - versionRefKey = "junit4" + version = JUNIT4_VERSION ) val TEST_ANDROIDX_JUNIT = LibraryRequirement( key = "test-androidx-junit", module = "androidx.test.ext:junit", - versionLiteral = "1.1.5" + version = TEST_ANDROIDX_JUNIT_VERSION ) val TEST_ANDROIDX_ESPRESSO_CORE = LibraryRequirement( key = "test-androidx-espresso-core", module = "androidx.test.espresso:espresso-core", - versionLiteral = "3.5.1" + version = TEST_ANDROIDX_ESPRESSO_CORE_VERSION ) val TEST_ANDROID_HILT = LibraryRequirement( key = "test-android-hilt", module = "com.google.dagger:hilt-android-testing", - versionLiteral = "2.48" + version = TEST_ANDROID_HILT_VERSION ) val TEST_ANDROID_UI_AUTOMATOR = LibraryRequirement( key = "test-android-uiautomator", module = "androidx.test.uiautomator:uiautomator", - versionLiteral = "2.2.0" + version = TEST_ANDROID_UI_AUTOMATOR_VERSION ) val TEST_ANDROID_MOCKWEBSERVER = LibraryRequirement( key = "test-android-mockwebserver", module = "com.squareup.okhttp3:mockwebserver", - versionLiteral = "4.12.0" + version = TEST_ANDROID_MOCKWEBSERVER_VERSION ) val TEST_ANDROIDX_RULES = LibraryRequirement( key = "test-androidx-rules", module = "androidx.test:rules", - versionLiteral = "1.5.0" + version = TEST_ANDROIDX_RULES_VERSION ) val TEST_COMPOSE_UI_JUNIT4 = @@ -175,42 +208,42 @@ object LibraryConstants { LibraryRequirement( key = "material", module = "com.google.android.material:material", - versionLiteral = "1.11.0" + version = MATERIAL_VERSION ) val OKHTTP3 = LibraryRequirement( key = "okhttp3", module = "com.squareup.okhttp3:okhttp", - versionLiteral = "4.12.0" + version = OKHTTP3_VERSION ) val ANDROIDX_APPCOMPAT = LibraryRequirement( key = "androidx-appcompat", module = "androidx.appcompat:appcompat", - versionLiteral = "1.6.1" + version = ANDROIDX_APPCOMPAT_VERSION ) val ANDROIDX_RECYCLERVIEW = LibraryRequirement( key = "androidx-recyclerview", module = "androidx.recyclerview:recyclerview", - versionLiteral = "1.3.2" + version = ANDROIDX_RECYCLER_VIEW_VERSION ) val ANDROIDX_FRAGMENT_KTX = LibraryRequirement( key = "androidx-fragment-ktx", module = "androidx.fragment:fragment-ktx", - versionLiteral = "1.6.2" + version = ANDROIDX_FRAGMENT_KTX_VERSION ) val ANDROIDX_NAVIGATION_FRAGMENT_KTX = LibraryRequirement( key = "androidx-navigation-fragment-ktx", module = "androidx.navigation:navigation-fragment-ktx", - versionLiteral = "2.7.6" + version = ANDROIDX_NAVIGATION_FRAGMENT_KTX_VERSION ) val ANDROIDX_UI_TOOLING = @@ -229,42 +262,42 @@ object LibraryConstants { LibraryRequirement( key = "androidx-activity-compose", module = "androidx.activity:activity-compose", - versionLiteral = "1.8.2" + version = ANDROIDX_ACTIVITY_COMPOSE_VERSION ) val ANDROIDX_CONSTRAINTLAYOUT = LibraryRequirement( key = "androidx-constraintlayout", module = "androidx.constraintlayout:constraintlayout", - versionLiteral = "2.1.4" + version = ANDROIDX_CONSTRAINT_LAYOUT_VERSION ) val KTOR_CLIENT_CORE = LibraryRequirement( key = "ktor-client-core", module = "io.ktor:ktor-client-core", - versionLiteral = "3.0.3" + version = KTOR_VERSION ) val KTOR_CLIENT_OKHTTP = LibraryRequirement( key = "ktor-client-okhttp", module = "io.ktor:ktor-client-okhttp", - versionLiteral = "3.0.3" + version = KTOR_VERSION ) val RETROFIT = LibraryRequirement( key = "retrofit", module = "com.squareup.retrofit2:retrofit", - versionLiteral = "2.11.0" + version = RETROFIT_VERSION ) val OKHTTP3_LOGGING_INTERCEPTOR = LibraryRequirement( key = "okhttp3-logging-interceptor", module = "com.squareup.okhttp3:logging-interceptor", - versionLiteral = "4.12.0" + version = OKHTTP3_LOGGING_INTERCEPTOR_VERSION ) val CORE_ANDROID_LIBRARIES = @@ -328,56 +361,56 @@ object PluginConstants { PluginRequirement( key = "kotlin-jvm", id = "org.jetbrains.kotlin.jvm", - versionRefKey = "kotlin" + version = KOTLIN_VERSION ) val KOTLIN_ANDROID = PluginRequirement( key = "kotlin-android", id = "org.jetbrains.kotlin.android", - versionRefKey = "kotlin" + version = KOTLIN_VERSION ) val KSP = PluginRequirement( key = "ksp", id = "com.google.devtools.ksp", - versionRefKey = "ksp" + version = KSP_VERSION ) val COMPOSE_COMPILER = PluginRequirement( key = "compose-compiler", id = "org.jetbrains.kotlin.plugin.compose", - versionRefKey = "kotlin" + version = KOTLIN_VERSION ) val ANDROID_APPLICATION = PluginRequirement( key = "android-application", id = "com.android.application", - versionRefKey = "androidGradlePlugin" + version = ANDROID_GRADLE_PLUGIN_VERSION ) val ANDROID_LIBRARY = PluginRequirement( key = "android-library", id = "com.android.library", - versionRefKey = "androidGradlePlugin" + version = ANDROID_GRADLE_PLUGIN_VERSION ) val KTLINT = PluginRequirement( key = "ktlint", id = "org.jlleitschuh.gradle.ktlint", - versionRefKey = "ktlint" + version = KTLINT_VERSION ) val DETEKT = PluginRequirement( key = "detekt", id = "io.gitlab.arturbosch.detekt", - versionRefKey = "detekt" + version = DETEKT_VERSION ) val KOTLIN_PLUGINS = diff --git a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogContentUpdater.kt b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogContentUpdater.kt index 00ee380..41c7381 100644 --- a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogContentUpdater.kt +++ b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogContentUpdater.kt @@ -116,10 +116,7 @@ class VersionCatalogContentUpdater { } is SectionEntryRequirement.LibraryRequirement -> { val parts = mutableListOf("module = \"${req.module}\"") - when { - req.versionRefKey != null -> parts.add("version.ref = \"${req.versionRefKey}\"") - req.versionLiteral != null -> parts.add("version = \"${req.versionLiteral}\"") - } + if (req.version != null) parts.add("version.ref = \"${req.version.key}\"") "${req.key} = { ${parts.joinToString(", ")} }" } is SectionEntryRequirement.BundleRequirement -> { @@ -127,7 +124,7 @@ class VersionCatalogContentUpdater { "${req.key} = [ $members ]" } is SectionEntryRequirement.PluginRequirement -> { - "${req.key} = { id = \"${req.id}\", version.ref = \"${req.versionRefKey}\" }" + "${req.key} = { id = \"${req.id}\", version.ref = \"${req.version.key}\" }" } } diff --git a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogUpdater.kt b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogUpdater.kt index 4035288..71a6850 100644 --- a/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogUpdater.kt +++ b/core/src/main/kotlin/com/mitteloupe/cag/core/generation/versioncatalog/VersionCatalogUpdater.kt @@ -5,6 +5,7 @@ import com.mitteloupe.cag.core.generation.CatalogInsertPosition import com.mitteloupe.cag.core.generation.filesystem.FileCreator import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.LibraryRequirement import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.PluginRequirement +import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.VersionRequirement import java.io.File data class SectionTransaction( @@ -23,8 +24,7 @@ sealed class SectionEntryRequirement(val header: String) { data class LibraryRequirement( override val key: String, val module: String, - val versionRefKey: String? = null, - val versionLiteral: String? = null + val version: VersionRequirement? = null ) : SectionEntryRequirement("libraries") data class BundleRequirement( @@ -35,7 +35,7 @@ sealed class SectionEntryRequirement(val header: String) { data class PluginRequirement( override val key: String, val id: String, - val versionRefKey: String + val version: VersionRequirement ) : SectionEntryRequirement("plugins") } @@ -101,7 +101,7 @@ class VersionCatalogUpdater( PluginRequirement( key = candidateAlias, id = desired.id, - versionRefKey = desired.versionRefKey + version = desired.version ) ) } @@ -141,8 +141,7 @@ class VersionCatalogUpdater( LibraryRequirement( key = candidateAlias, module = desired.module, - versionRefKey = desired.versionRefKey, - versionLiteral = desired.versionLiteral + version = desired.version ) ) } @@ -155,7 +154,9 @@ class VersionCatalogUpdater( listOf( SectionTransaction( insertPositionIfMissing = CatalogInsertPosition.Start, - requirements = dependencyConfiguration.versions + requirements = + (dependencyConfiguration.versions + pluginRequirements.versions + libraryRequirements.versions) + .distinct() ), SectionTransaction( insertPositionIfMissing = CatalogInsertPosition.End, @@ -193,7 +194,7 @@ class VersionCatalogUpdater( PluginRequirement( key = desired.key, id = desired.id, - versionRefKey = desired.versionRefKey + version = desired.version ) } @@ -202,12 +203,13 @@ class VersionCatalogUpdater( LibraryRequirement( key = desired.key, module = desired.module, - versionRefKey = desired.versionRefKey, - versionLiteral = desired.versionLiteral + version = desired.version ) } - val versionRequirements = dependencyConfiguration.versions + val versionRequirements = + (dependencyConfiguration.versions + pluginRequirements.versions + libraryRequirements.versions) + .distinct() updateVersionCatalogIfPresent( projectRootDir = projectRootDir, @@ -270,4 +272,14 @@ class VersionCatalogUpdater( module to alias } } + + private val List.versions + get() = + mapNotNull { + when (it) { + is LibraryRequirement -> it.version + is PluginRequirement -> it.version + else -> null + } + } } diff --git a/core/src/test/kotlin/com/mitteloupe/cag/core/GeneratorTest.kt b/core/src/test/kotlin/com/mitteloupe/cag/core/GeneratorTest.kt index c87c39c..6fb5227 100644 --- a/core/src/test/kotlin/com/mitteloupe/cag/core/GeneratorTest.kt +++ b/core/src/test/kotlin/com/mitteloupe/cag/core/GeneratorTest.kt @@ -471,7 +471,7 @@ class GeneratorTest { androidGradlePlugin = "8.12.2" composeBom = "2025.08.01" composeNavigation = "2.9.3" - composeCompiler = "1.5.8" + androidxActivityCompose = "1.8.2" [libraries] $existingLibraries @@ -483,7 +483,7 @@ class GeneratorTest { compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "composeNavigation" } compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } - androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.8.2" } + androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivityCompose" } [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } @@ -527,12 +527,12 @@ class GeneratorTest { val expectedContent = """ [versions] - kotlin = "2.2.10" - ksp = "2.2.10-2.0.2" compileSdk = "35" minSdk = "24" targetSdk = "35" androidGradlePlugin = "8.12.2" + kotlin = "2.2.10" + ksp = "2.2.10-2.0.2" [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } @@ -543,11 +543,6 @@ class GeneratorTest { """.trimIndent() - println("Actual (compose disabled):") - println(catalogContent) - println("Expected (compose disabled):") - println(expectedContent) - assertEquals( "Generated catalog should match expected content (no compose)", expectedContent, diff --git a/core/src/test/kotlin/com/mitteloupe/cag/core/generation/VersionCatalogUpdaterTest.kt b/core/src/test/kotlin/com/mitteloupe/cag/core/generation/VersionCatalogUpdaterTest.kt index 53e5c95..d36f5a0 100644 --- a/core/src/test/kotlin/com/mitteloupe/cag/core/generation/VersionCatalogUpdaterTest.kt +++ b/core/src/test/kotlin/com/mitteloupe/cag/core/generation/VersionCatalogUpdaterTest.kt @@ -7,6 +7,7 @@ import com.mitteloupe.cag.core.generation.versioncatalog.LibraryConstants import com.mitteloupe.cag.core.generation.versioncatalog.PluginConstants import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.LibraryRequirement import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.PluginRequirement +import com.mitteloupe.cag.core.generation.versioncatalog.SectionEntryRequirement.VersionRequirement import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogConstants import com.mitteloupe.cag.core.generation.versioncatalog.VersionCatalogUpdater import org.junit.Assert.assertEquals @@ -27,7 +28,12 @@ class VersionCatalogUpdaterTest { fun `Given no catalog file when updateVersionCatalogIfPresent then does nothing`() { // Given val projectRoot = createTempDirectory(prefix = "noCatalog").toFile() - val dependencyConfiguration = DependencyConfiguration() + val dependencyConfiguration = + DependencyConfiguration( + versions = emptyList(), + libraries = emptyList(), + plugins = emptyList() + ) // When classUnderTest.updateVersionCatalogIfPresent(projectRootDir = projectRoot, dependencyConfiguration = dependencyConfiguration) @@ -51,9 +57,6 @@ class VersionCatalogUpdaterTest { [versions] kotlin = "2.2.10" ksp = "2.2.10-2.0.2" - compileSdk = "35" - minSdk = "24" - targetSdk = "35" androidGradlePlugin = "8.12.2" [plugins] @@ -66,7 +69,7 @@ class VersionCatalogUpdaterTest { val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.KOTLIN_VERSIONS + VersionCatalogConstants.ANDROID_VERSIONS, + versions = emptyList(), libraries = emptyList(), plugins = PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS ) @@ -104,6 +107,7 @@ class VersionCatalogUpdaterTest { minSdk = "23" targetSdk = "35" androidGradlePlugin = "8.12.2" + ksp = "2.2.10-2.0.2" [plugins] android-application = { id = "com.android.application", version = "1.0.0" } @@ -148,6 +152,7 @@ class VersionCatalogUpdaterTest { minSdk = "24" targetSdk = "35" androidGradlePlugin = "8.12.2" + ksp = "2.2.10-2.0.2" [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } @@ -191,7 +196,7 @@ class VersionCatalogUpdaterTest { kotlin = "2.2.10" compileSdk = "35" minSdk = "24" - targetSdk = "35" + ksp = "2.2.10-2.0.2" androidGradlePlugin = "8.12.2" [plugins] @@ -204,7 +209,7 @@ class VersionCatalogUpdaterTest { val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.ANDROID_VERSIONS, + versions = emptyList(), libraries = emptyList(), plugins = PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS ) @@ -234,26 +239,18 @@ class VersionCatalogUpdaterTest { """ [versions] agp = "35" - kotlin = "2.2.10" - ksp = "2.2.10-2.0.2" - compileSdk = "35" - minSdk = "24" - targetSdk = "35" androidGradlePlugin = "8.12.2" [plugins] android-library = { id = "com.android.library", version.ref = "agp" } - kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } - kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } - ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } """.trimIndent() + "\n" val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.KOTLIN_VERSIONS + VersionCatalogConstants.ANDROID_VERSIONS, + versions = emptyList(), libraries = emptyList(), - plugins = PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS + plugins = PluginConstants.ANDROID_PLUGINS ) // When @@ -282,19 +279,11 @@ class VersionCatalogUpdaterTest { kotlin = "2.2.10" compileSdk = "35" minSdk = "24" - ksp = "2.2.10-2.0.2" - targetSdk = "35" - androidGradlePlugin = "8.12.2" composeBom = "2025.08.01" composeNavigation = "2.9.3" - composeCompiler = "1.5.8" + androidxActivityCompose = "1.8.2" [plugins] - kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } - kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } - ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } - android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } - android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } [libraries] @@ -306,19 +295,14 @@ class VersionCatalogUpdaterTest { compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "composeNavigation" } compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } - androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.8.2" } + androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivityCompose" } """.trimIndent() + "\n" val dependencyConfiguration = DependencyConfiguration( - versions = - VersionCatalogConstants.KOTLIN_VERSIONS + - VersionCatalogConstants.ANDROID_VERSIONS + - VersionCatalogConstants.COMPOSE_VERSIONS, + versions = emptyList(), libraries = LibraryConstants.COMPOSE_LIBRARIES, - plugins = - PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS + - PluginConstants.COMPOSE_COMPILER + plugins = listOf(PluginConstants.COMPOSE_COMPILER) ) // When @@ -329,7 +313,7 @@ class VersionCatalogUpdaterTest { } @Test - fun `Given coroutines enabled when updateVersionCatalogIfPresent then adds coroutine dependencies`() { + fun `Given coroutines when updateVersionCatalogIfPresent then adds coroutine dependencies`() { // Given val (projectRoot, catalogFile) = createProjectWithCatalog( @@ -347,35 +331,17 @@ class VersionCatalogUpdaterTest { kotlin = "2.2.10" compileSdk = "35" minSdk = "24" - ksp = "2.2.10-2.0.2" - targetSdk = "35" - androidGradlePlugin = "8.12.2" - - [plugins] - kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } - kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } - ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } - android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } - android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" } + kotlinxCoroutinesCore = "1.7.3" [libraries] - androidx-core-ktx = { module = "androidx.core:core-ktx", version = "1.12.0" } - androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version = "2.7.0" } - androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.6.1" } - kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.7.3" } - material = { module = "com.google.android.material:material", version = "1.11.0" } - okhttp3 = { module = "com.squareup.okhttp3:okhttp", version = "4.12.0" } - androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version = "1.3.2" } - androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version = "1.6.2" } - androidx-navigation-fragment-ktx = { module = "androidx.navigation:navigation-fragment-ktx", version = "2.7.6" } - androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version = "2.1.4" } + kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" } """.trimIndent() + "\n" val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.KOTLIN_VERSIONS + VersionCatalogConstants.ANDROID_VERSIONS, - libraries = LibraryConstants.CORE_ANDROID_LIBRARIES + LibraryConstants.VIEW_LIBRARIES, - plugins = PluginConstants.KOTLIN_PLUGINS + PluginConstants.ANDROID_PLUGINS + versions = listOf(VersionCatalogConstants.KOTLINX_COROUTINES_CORE_VERSION), + libraries = listOf(LibraryConstants.KOTLINX_COROUTINES_CORE), + plugins = emptyList() ) // When @@ -391,7 +357,7 @@ class VersionCatalogUpdaterTest { val projectRoot = createTempDirectory(prefix = "newCatalog").toFile() val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.KOTLIN_VERSIONS, + versions = emptyList(), libraries = LibraryConstants.CORE_ANDROID_LIBRARIES.take(2), plugins = PluginConstants.KOTLIN_PLUGINS.take(2) ) @@ -428,7 +394,7 @@ class VersionCatalogUpdaterTest { ) val dependencyConfiguration = DependencyConfiguration( - versions = VersionCatalogConstants.KOTLIN_VERSIONS, + versions = emptyList(), libraries = LibraryConstants.CORE_ANDROID_LIBRARIES.take(1), plugins = PluginConstants.KOTLIN_PLUGINS.take(1) ) @@ -440,14 +406,14 @@ class VersionCatalogUpdaterTest { assertEquals( "existing-plugin", classUnderTest.getResolvedPluginAliasFor( - PluginRequirement("existing-plugin", "com.example.existing", "kotlin") + PluginRequirement("existing-plugin", "com.example.existing", VersionRequirement("kotlin", "1.1.0")) ) ) assertEquals("kotlin-jvm", classUnderTest.getResolvedPluginAliasFor(PluginConstants.KOTLIN_JVM)) assertEquals( "existing-library", classUnderTest.getResolvedLibraryAliasForModule( - LibraryRequirement("existing-library", "com.example:existing", versionLiteral = "1.0.0") + LibraryRequirement("existing-library", "com.example:existing") ) ) assertEquals("androidx-core-ktx", classUnderTest.getResolvedLibraryAliasForModule(LibraryConstants.ANDROIDX_CORE_KTX)) @@ -457,7 +423,12 @@ class VersionCatalogUpdaterTest { fun `Given no catalog file when updateVersionCatalogIfPresent then resolved mappings remain empty`() { // Given val projectRoot = createTempDirectory(prefix = "noCatalog").toFile() - val dependencyConfiguration = DependencyConfiguration() + val dependencyConfiguration = + DependencyConfiguration( + versions = emptyList(), + libraries = emptyList(), + plugins = emptyList() + ) // When classUnderTest.updateVersionCatalogIfPresent(projectRootDir = projectRoot, dependencyConfiguration = dependencyConfiguration)