Is it possible to create a custom buildsrc in Grad...
# gradle
n
Is it possible to create a custom buildsrc in Gradle 4.9 using the Kotlin DSL?
a
Yes
That's using 4.9-RC-1
There are still some weird issues/limitations with cross-project (as in "gradle project") class loaders though
n
Seems that buildSrc in the root project isn't accessible in sub projects 🙁.
a
It is and isn't - I declare a lot of functions in my buildSrc that are used in the subprojects
But there are some limitions with plugins and classloaders (it's a known issue that's being addressed)
I had to make
configureAndroidLib
an inline function though due to classloader issues
n
Trying to make the following accessible from the buildSrc in all projects:
Copy code
object Version {
    val kotlin = "1.2.51"
    val dokka = "0.9.14"
}
a
Yea that should be fine. My dependency declarations: https://github.com/NextFaze/dev-fun/blob/master/buildSrc/src/main/kotlin/dependencies.kt Usage is as expected in subproject `api(Dependency.supportAppCompat)`: https://github.com/NextFaze/dev-fun/blob/master/devfun-menu/build.gradle.kts#L26
Oh, one thing I would suggest is to not use a package in your
buildSrc
project
🆗 1
1
There were some weird issues when trying to reference things in the root project
n
The buildSrc still isn't accessible in the sub projects, only accessible in the root project.
g
@napperley No, everything should work. Try to build your project. IDE has some problems with buildSrc on dependencies change
n
So buildSrc dependency issues get resolved by executing the build task?
g
it’s IDE only problem
Give me a minute, I will find this issue
But we use buildSrc and it works properly for us, just not so smooth as could be
So build is not enough, you should somehow trigger build dependencies reloading
Will be fixed in 0.19
This is issue that I reported about this problem on Kotlin issue tracker https://youtrack.jetbrains.com/issue/KT-25354
📋 1
👍 1
n
Using the terminal to run Gradle tasks as a temporary workaround to the issue ☝️.
g
@napperley Just follow workaround from the issue:
One workaround is to make a change in the plugins or buildscript block of the edited script.
After that IDE will cache correct version of classpath with your buildSrc depenedencies
n
Made the changes but only some of the errors are resolved. Still end up with the yellow banner appearing.
a
Are you using Android Studio or IDEA?
FTR I'm using Android Studio 3.3 Canary 3 and it's generally quite reliable
If I change things in the buildSrc project sometimes I need to rebuild and restart the IDE for the warnings/errors to resolve (or using aforementioned workaround)
n
Using IntelliJ (v2018.2).