Has anyone configured buildSrc within an android p...
# gradle
b
Has anyone configured buildSrc within an android project to depend on a limited amount of code from your main app module? I have two classes from my main app module that I want to generate code based off. I googled and saw folks mention that you just need to specify the files from your main module in the
buildSrc
sourceSet, but I could not find an example of how to do this. I am playing around with
buildSrc
sourceSets right now, but would appreciate it if anyone has some code I could reference to save a few cycles
Eh, this approach seems problematic. I'd like to specify individual files to add to the sourceset, but based on naming it looks like you can just specify directories (both are File, but I'd expect an error based on naming). I tried:
Copy code
sourceSets {
    val main by getting
    println("currentDir: ${File(".").absolutePath}")
    main.java.srcDirs += File("../mobile/src/main/java/com/theathletic/analytics/newarch")
    main.java.srcDirs += File("../mobile/src/main/java")
}
I am going to try just copying the two files I need into buildSrc. Open to any thoughts on best practices here
copying the files out of the main module into buildSrc worked (since the classes did not have external dependencies) 👍
Eh it works with manual intervention. You can use
settings.gradle.kts
within buildSrc as an opportunity to run a script before buildSrc or anything else is compiled. This works fine from CLI, but Android Studio freaks out if you try to access anything here
Workaround hack is to wrap initialization script in try-catch so AndroidStudio works properly and you can copy files between projects before initial build