Mark
08/06/2024, 11:05 AMcomposeCompiler { }
in each appropriate module. My app has over 20 such modules. Is there a way to declare this just once for the project?Stylianos Gakis
08/06/2024, 11:10 AMStylianos Gakis
08/06/2024, 11:10 AMStylianos Gakis
08/06/2024, 11:12 AMStylianos Gakis
08/06/2024, 11:14 AMStylianos Gakis
08/06/2024, 11:15 AMshikasd
08/06/2024, 11:43 AMsubprojects/allprojects
block in the root gradle fileshikasd
08/06/2024, 11:44 AMMark
08/06/2024, 11:51 AMsubprojects {
project.plugins.applyBaseConfig(project)
}
// <https://www.droidcon.com/2022/03/11/reducing-gradle-boilerplate-in-multi-module-android-projects/>
fun BaseExtension.baseConfig() {
compileSdkVersion(AndroidSdk.compile)
defaultConfig.apply {
minSdk = AndroidSdk.min
targetSdk = AndroidSdk.target
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("<http://proguard-rules.pro|proguard-rules.pro>")
}
compileOptions.apply {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
/**
* Apply configuration settings that are shared across all modules.
*/
fun PluginContainer.applyBaseConfig(project: Project) {
whenPluginAdded {
when (this) {
is AppPlugin -> {
project.extensions
.getByType<AppExtension>()
.apply {
baseConfig()
}
}
is LibraryPlugin -> {
project.extensions
.getByType<LibraryExtension>()
.apply {
baseConfig()
}
}
}
}
}
Stylianos Gakis
08/06/2024, 11:51 AMMark
08/06/2024, 12:35 PMproject.composeCompiler { ... }
inside the baseConfig
extension function, but that doesn’t work. Just seeing if I can get it working with my existing approach before trying something new.Stylianos Gakis
08/06/2024, 12:36 PMMark
08/06/2024, 12:38 PMStylianos Gakis
08/06/2024, 12:42 PMMark
08/06/2024, 12:54 PMbuildFeatures { compose = true }
the app still builds and runs fine. Is that to be expected? Perhaps something else is setting that implicitly.Mark
08/06/2024, 1:07 PMextensions.configure<ComposeCompilerGradlePluginExtension> { ... }
I get:
Extension of type 'ComposeCompilerGradlePluginExtension' does not exist
So I guess I need to register it somewhere?Mark
08/06/2024, 1:40 PMApplicationPlugin
& ApplicationExtension
instead of the App*
equivalents. Is it safe to just switch to those Application*
types? This enables using CommonExtension
as the receiver for the baseConfig
function.Arsildo Murati
08/06/2024, 4:36 PMMark
08/06/2024, 5:08 PMfun PluginContainer.applyBaseConfig(project: Project) {
whenPluginAdded {
when (this) {
is ApplicationPlugin -> {
project.extensions
.getByType<ApplicationExtension>()
.apply {
println("found ApplicationExtension")
(this as BaseExtension).baseConfig()
}
}
is LibraryPlugin -> {
project.extensions
.getByType<LibraryExtension>()
.apply {
println("found LibraryExtension")
baseConfig()
}
}
}
}
}
then the app modules are not found. I need to use AppPlugin/AppExtension. Oh but this seems to work:
is AppPlugin -> {
project.extensions
.getByType<ApplicationExtension>()