0

Gradle - 8.2.1, AGP - 8.0.2, Kotlin - 1.9.0

buildSrc/build.gradle.kts

plugins {
    `kotlin-dsl`
}
dependencies {
    implementation("com.android.tools.build:gradle-api:8.0.2")
}

gradle/support/common-app-config.gradle.kts

plugins {
    id("com.android.application")
    ...
}
android {
    ...
}
dependencies {
    implementation(project(":feature-one"))
    implementation(project(":feature-two"))
    ...
}

Similarly, gradle/support/common-lib-config.gradle.kts

plugins {
    id("com.android.library")
    ...
}
android {
    ...
}
dependencies {
    implementation(project(":platform"))
    ...
}

Also, gradle/support/common-dependencies.gradle.kts

dependencies {
    implementation("androidx", "lifecycle", "navigation"... )
    /** You get the gist of this block **/
    ...
}

Is there a clean approach to centralizing the android {} blocks for application and library, separately is still fine, as well as dependencies {} block for re-use ?

So far, app/build.gradle.kts

apply {
    from(file("${rootProject.projectDir}/gradle/support/common-app-config.gradle.kts"))
}

fails with "Unresolved reference : android", despite declaring the "com.android.application" plugin in the common-app-config.gradle.kts file.

AndroidRocks
  • 292
  • 4
  • 16
  • Why have you put the convention plugins in the `gradle/support/` directory? Usually they go in `buildSrc/src/main/kotlin/` – aSemy Jul 18 '23 at 06:25
  • Version-catalogs appear to be visible only to outer build-script files - `./build.gradle.kts`, `./settings.gradle.kts`, `./buildSrc/**.gradle.kts`, ( Convention plugins folder, let's say ) `./gradle/support/**.gradle.kts`, but version-catalogs are not visible inside the convention plugins folders `./gradle/support/src/main/kotlin/*`, primarily because kotlin-dsl extract plugins {} block from `./gradle/support/src/main/kotlin/**.gradle.kts` files into `./gradle/support/build/kotlin-dsl/plugins-blocks/extracted/**.gradle.kts`, and that's where version-catalogs aren't resolving ? – AndroidRocks Jul 18 '23 at 17:35

0 Answers0