Andrzej Zabost
07/30/2025, 12:16 PMbuildscript
block is used or not (or, at least, that seems to be the difference).
I'm sharing the post from #CJYS1DAP5 for visibility because I assume the problem may be more generic and not necessarily Android related.
https://gradle-community.slack.com/archives/CJYS1DAP5/p1753877427121339Vampire
07/30/2025, 12:26 PMbuildscript
block from the root build script to the app
buildscript
⢠or you add the plugin version in the version catalog, and replace the buildscript
block in the root project with plugins { alias(libs.plugins.room) apply false }
Does it work with the first and not work with the second?Andrzej Zabost
07/30/2025, 12:35 PMbuildscript
block from the root build script to the app
buildscript
FAILURE: Build failed with an exception.
* Where:
Build file '/blablabla/app/build.gradle.kts' line: 13
* What went wrong:
Plugin [id: 'androidx.room'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (plugin dependency must include a version number for this source)
----
> ⢠or you add the plugin version in the version catalog, and replace the buildscript
block in the root project with plugins { alias(libs.plugins.room) apply false }
Same as before the change:
> Task :app:kspDebugKotlin
w: [ksp] Schema export directory was not provided to the annotation processor (etc.)
----
Andrzej Zabost
07/30/2025, 12:52 PMVampire
07/30/2025, 12:53 PMplugins
and use apply(plugin = "androidx.room")
on top-level insteadAndrzej Zabost
07/30/2025, 1:00 PMgit clean -xdf
3. ./gradlew :app:assembleDebug --rerun-tasks --no-build-cache --no-configuration-cache
4. all good
5. rm -r app/schemas
to remove the generated DB schema file
6. switching to the branch where I'm getting the warning ("method 2")
7. IF
a. I do run git clean -xdf
now
i. ./gradlew :app:assembleDebug --rerun-tasks --no-build-cache --no-configuration-cache
ii. schema file is not generated by the plugin
b. I don't run git clean -xdf
now
i. ./gradlew :app:assembleDebug --rerun-tasks --no-build-cache --no-configuration-cache
ii. schema file somehow comes back š¤ÆAndrzej Zabost
07/30/2025, 1:05 PMAh sorry, for the first of my bullet-points also remove it fromNot sure if I understood it perfectly - here's how theand useplugins
on top-level insteadapply(plugin = "androidx.room")
app/build.gradle.kts
looks now (part of it)
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath(libs.room.plugin)
}
}
plugins {
// no more Room plugin here
}
apply(plugin = "androidx.room") // added this
// same as before
android {
room {
schemaDirectory("$projectDir/schemas")
}
}
and root build.gradle.kts
is deleted
Then I'm getting:
> Configure project :app
e: file:///blablabla/app/build.gradle.kts:55:5: Unresolved reference: room
e: file:///blablabla/app/build.gradle.kts:56:9: Unresolved reference: schemaDirectory
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/azabost/projects/quests/modularization-quest/app/build.gradle.kts' line: 55
* What went wrong:
Script compilation errors:
Line 55: room {
^ Unresolved reference: room
Line 56: schemaDirectory("$projectDir/schemas")
^ Unresolved reference: schemaDirectory
Vampire
07/30/2025, 1:15 PMVampire
07/30/2025, 1:20 PMroom { ... }
inside android { ... }
is just visual clutter.
room
is an extension on Project
, not on the android extension, so you should anyway move it to top-level.Andrzej Zabost
07/30/2025, 1:20 PMVampire
07/30/2025, 1:21 PMroom {
by configure<RoomExtension> {
, then the configuraiton works also with the apply
Andrzej Zabost
07/30/2025, 1:21 PMBtw.Yeah, I figured out. I was following the official guide, which is obviously far from ideal...insideroom { ... }
is just visual clutter.android { ... }
Vampire
07/30/2025, 1:22 PMAndrzej Zabost
07/30/2025, 1:24 PMroom {
by configure<RoomExtension> {
, then the configuraiton works also with the apply
With this, everything works fine, i.e. no KSP warning, and the schema gets generated correctlyVampire
07/30/2025, 1:24 PMVampire
07/30/2025, 1:25 PMAndrzej Zabost
07/30/2025, 1:25 PMBut adding the extension to top-level but then documenting to configure it within the android block is very inconsistent and wrong.Fully agreed. Can't count how many times I was mislead by this kind of documentation back in the groovy times, when it was less obvious.
Vampire
07/30/2025, 1:25 PMVampire
07/30/2025, 1:25 PMVampire
07/30/2025, 1:26 PMAndrzej Zabost
07/30/2025, 1:31 PMplugins {}
block execution
e.g.
// app/build.gradle.kts
plugins {
id("com.android.application")
// a few others
id("androidx.room") // <--- now the plugin's apply(T) runs, no?
}
So my assumption would be that adding the plugin to root project's buildscript
/ classpath wouldn't make any difference, because the plugin wouldn't really run at that point š¤Andrzej Zabost
07/30/2025, 1:33 PMVampire
07/30/2025, 1:35 PMVampire
07/30/2025, 1:35 PMVampire
07/30/2025, 1:36 PMplugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.room) apply false
}
in the root project and
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.room)
}
in the subprojectVampire
07/30/2025, 1:37 PMVampire
07/30/2025, 1:37 PMplugins {
alias(libs.plugins.room) apply false
}
for that, or just don't do it at all if you have no technical reason to do soVampire
07/30/2025, 1:39 PMalias(libs.plugins.room) apply false
is like using the buildscript
block to add the plugin to the classpath
alias(libs.plugins.room)
with the plugin already being in the classpath by some parent classloader is like just calling apply(...)
alias(libs.plugins.room)
with the plugin not being in the classpath yet is like a combination of the above twoAndrzej Zabost
07/30/2025, 1:40 PMBtw. why do you add it to the root project via buildscript block at all?I did it because in the other project they still have a lot of plugins in the root
buildscript
and I was exploring my options. I wanted to see if I can add the plugin and keep their old convention until they migrate away the whole root build.gradle.kts
from buildscript
usageVampire
07/30/2025, 1:40 PMplugins { ... }
block to apply and it is the idiomatic and recommended way.Andrzej Zabost
07/30/2025, 1:41 PMalias(libs.plugins.room) apply false
is like using the buildscript
block to add the plugin to the classpath
Yes, and the documentation for that plugin suggests doing so i.e. the apply false
approach in root - that's why I was experimenting with classpath
in buildscript
as a replacement for thatVampire
07/30/2025, 1:43 PMVampire
07/30/2025, 1:43 PMAndrzej Zabost
07/30/2025, 1:43 PMIf you would also move whatever plugin it requires - probably the android plugin - to the root build script classloader it would probably also work.If you see the complete example, there actually should be Android plugin in root, inherited from `buildSrc/build.gradle.kts`(correct me if I'm wrong that root's classloader's parent is the
buildSrc
's classloader šµ )Vampire
07/30/2025, 1:44 PMVampire
07/30/2025, 1:45 PMVampire
07/30/2025, 1:45 PMAndrzej Zabost
07/30/2025, 1:45 PMAndrzej Zabost
07/30/2025, 1:46 PMAndrzej Zabost
07/30/2025, 1:46 PMAndrzej Zabost
07/30/2025, 2:04 PMgit clean -xdf
makes a difference when switching branches? How come the schema file gets restored despite the --rerun-tasks --no-build-cache --no-configuration-cache
?Vampire
07/30/2025, 2:09 PMAndrzej Zabost
07/30/2025, 2:11 PMAndrzej Zabost
07/30/2025, 2:38 PMAndrzej Zabost
07/30/2025, 2:49 PMplugins {
alias(libs.plugins.room) apply false
}
in root build.gradle.kts
on top of the working example
then it stops working š« Vampire
07/30/2025, 2:52 PMVampire
07/30/2025, 2:53 PMVampire
07/30/2025, 2:54 PMAndrzej Zabost
07/30/2025, 2:55 PMVampire
07/30/2025, 3:05 PMVampire
07/30/2025, 3:05 PMVampire
07/30/2025, 3:06 PMVampire
07/30/2025, 3:06 PMVampire
07/30/2025, 3:07 PM