I am writing a KMM app, currently using Android Studio Giraffe and Gradle 8.0. The project includes some simple custom tasks to generate kotlin source code, so I want to mark the relevant directories as “generated sources root”. To avoid the markers disappearing when I clean the build I want to apply the markers from my gradle script. According to the docs this should be quite easy with the idea plugin, by adding this to the relevant module’s build.gradle.kts:
plugins {
...
idea
}
idea {
module {
generatedSourceDirs += File("$buildDir/$licenceInfoDestPath")
}
}
But this doesn’t work. I can’t invoke idea like that. The only idea symbol available in the script at all is the property in the plugins block, which is shorthand for id("org.gradle.idea"), and it’s invalid elsewhere in the script.
I’ve been going round in circles with Bard, trying all sorts of things, like adding idea to the top-level script’s plugins instead of or in addition to the module level, moving the idea {...} block to the top-level too, using apply instead of id. Nothing works.
Then I thought I might be able to get an instance of IdeaModule from a custom task, but Bard got that all wrong too, suggesting I can find it in project.modules, but project doesn’t have a modules field.
Bard’s only other suggestion is to forget the idea plugin and “communicate that information to the IDE,” by some other means (including leveraging a gradle plugin, doh!).
Can anyone offer a working solution to this problem?
Bard is as useless as ChatGPT for anything where you do not know the answer already.
Those AI assistents are great in giving answers that look correct, but horribly bad in giving answers that are correct.
The only thing you can use such tools for imho is, for things you could as well do yourself but are too lazy (the good lazy, not the bad one) as you have to understand what it shows you and extract the valuable information, fixing the non-sense it made up from nowhere additionally.
Besides that, the code that you showed should compile just fine (except for the += which is ambiguous), and it does if I paste it into my play project. If it does not for you, please provide a more complete example of what is not working.
Thanks for the help, and sorry about the delay i replying. Gmail thought the emails from this site were spam for some reason; it doesn’t usually get it that badly wrong, so I don’t check my spam folder very often.
Anyway, the above code does work now, or at least did when I tried to replicate the issue in a new project for a bug report, and replaced the += with separate = and + expressions. I’ve had such a week, I can’t remember whether I got it working in my real app, but I discovered I didn’t need to. The markers automatically get applied by doing this (for the shared module):
kotlin {
...
sourceSets {
val commonMain by getting {
...
kotlin.srcDirs("src/commonMain/kotlin", "$buildDir/generated/source/.../kotlin")
}
}
}