Hi All, I have a multi gradle project and i have ...
# community-support
s
Hi All, I have a multi gradle project and i have a requirement that i want to add common dependencies, publications, sonarqube etc at parent level and all the child projects should refer the dependencies publication, sonarqube from parent and use it without duplicating the common dependecnies, i tried multiple approaches such as buildSrc, etc, but nothing has worked, can you help me sample use case tried below approaches • create the build.gradle in buildSrc and add the things, but when i run the child build, the parent defines jar is not acceesable from child and i get an error
d
If you just want to have the versions in a single place have a look at version catalogs https://docs.gradle.org/current/userguide/version_catalogs.html However, if you meant that you have multiple modules in your project that should share the same dependencies and you want a single place to control those I can suggest 2 ways: • Have an empty module with just dependencies declared and add that single module as dependency to all the modules that need to have those dependencies • Write build convention plugins in a build-logic folder and apply the shared dependency by just including your convention plugin in the project https://docs.gradle.org/current/samples/sample_publishing_convention_plugins.html
s
Thank you so much for providing the insights, yes i have gone thorough docs and found that the java conventions may works and then created a plugin and used it, it worked just like that
n
you can check build-logic concept to centralize Gradle logic across your project https://github.com/android/nowinandroid/tree/main/build-logic
šŸ™Œ 1
d
If you use Kotlin instead of Java you can write Gradle Plugins and Gradle build files with the same language
v
That's one of the worst reasons for using Kotlin I ever heard. šŸ˜„ I would always use Java for any published plugin that should be as compatible as possible and Kotlin for any internal build logic stuff. šŸ™‚
d
@Vampire?? Kotlin and java are compatible
v
But Kotlin and Kotlin are not. Gradle controls the Kotlin in the runtime environment and so you have to make sure you are compatible in that regards. For public plugins I would always use Java and there the lowest version supported by the lowest version of Gradle that should be supported, so basically for public plugins I would currently always use Java 8 for maximum compatibility and least hassle and problems. šŸ™‚
d
I don't think that makes any sense mate :-) I usually really value your opinions on Gradle but here I've no idea of what you are talking about. I'd stay away from Java 8 other than using it as a target JVM with kotlin. But I don't want to get in an argument and it is off topic in respect to the question OP asked. Speaking of which: he isn't building a public plugin, he's building a local one for his project build. And using the same language for both the scripting and the plugin makes perfect sense to me.
v
FWIW, I think your statement about using Kotlin was off-topic already, that was not at all the topic here. šŸ™‚ And well, you don't have to agree. It's just a painful learning through experience by me and also some other Gradle plugin authors and experts. But like always, I just state my experience and opinion, what you make out of it is up to you, you have to live with the consequences. šŸ™‚