Marek
06/02/2025, 6:18 PMext.compileSdk = 23
then subprojects could access it via rootProject.ext.compileSdk
. Now moved the common plugin configurations to convention plugins in an included build. Say in the included build I have now
object Constants {
val compileSdk = 23
}
I use this value in the convention plugins, but for legacy reasons this value is also needed in some other buildscript in the project. I don't want to have it duplicated just for that. I think I am able to read that value directly in *.kts
files but not in .gradle
files. (Why?) I have figured out I can create some kind of ConstantsConventionPlugin
class ConstantsConventionPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.extensions.extraProperties.set("ANDROID_COMPILE_SDK", Constants.compileSdk)
}
}
Can this be avoided? Is there a better alternative?ephemient
06/02/2025, 6:22 PMConstants.compileSdk
in build scripts just like you would any other codeMarek
06/02/2025, 6:23 PMephemient
06/02/2025, 6:23 PMephemient
06/02/2025, 6:24 PMConstants.$INSTANCE.compileSdk
but basically the same thingMarek
06/02/2025, 6:27 PMMarek
06/02/2025, 7:09 PM*.kts
but not in *.gradle
is that in every *.kts where I needed it, it already had one of the plugins from the included module applied. However I had none applied in the *.gradle file where I tried. Which means I can make a dummy, marker plugin that does nothing just to get my Constants
on the classpath.ephemient
06/02/2025, 8:07 PMplugins { id('...') apply false }
to just get it into the buildscript classpathVampire
06/02/2025, 9:33 PMVampire
06/02/2025, 9:34 PMext
/ extra
properties you should feel dirty. They are practically always just a work-around for not doing something properly. 🙂Vampire
06/02/2025, 9:36 PMephemient
06/02/2025, 9:37 PMint
while version catalogs give you strings, but in general yesephemient
06/02/2025, 9:40 PMMarek
06/03/2025, 6:21 AMbuild.gradle.kts
defines the plugin ids and the corresponding classes implementing those. However in the setting plugin I need to repeat those plugin ids.
Ideally would be good to have possibility to enforce it on some interface level. Say every convention plugin would have to implement certain check to be applied as settings plugin.
But at least I would like to be able to reference those plugin ids both in the settings plugin and in the convention plugins buildscript.