Peter
06/20/2024, 12:05 PM:buildSrc to included build, but I can't reference my constants in submodules now. What am I missing? Code in 🧵Peter
06/20/2024, 12:10 PMapp/build.gradle.kts
build-logic/build.gradle.kts
build-logic/src/main/kotlin/Versions.kt
settings.gradle.kts
app/build.gradle.kts:
plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.android.application)
}
android {
val java = Versions.java <-- Unresolved reference
compileOptions {
targetCompatibility = java
sourceCompatibility = java
}
// ...
}
Versions.kt
object Versions {
val java = JavaVersion.VERSION_17
}
settings.gradle.kts:
rootProject.name = "My project"
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
include(":app")
includeBuild("build-logic")Vampire
06/20/2024, 12:55 PMbuildSrc classes and dependencies are always available in all buildscripts as they are added to a parent classloader which has its pros but mostly cons.
Things from an included build are only built and added to the classpath if you actually use them. That is either declare a buildscript dependency on them or applying a plugin coming from them which is why your Versions class is not available currently.
But using a Versions class like that is bad practice anyway due to various reasons. Better use the version catalog feature, especially with a TOML file.