I am using Gradle to orchestrate build of multiple related projects that are in different technologies.
myproject
├── build.gradle.kts
├── buildSrc
├── service-0
├── gradle
├── gradlew
├── gradlew.bat
├── service-1
├── service-2
├── service-3
└── settings.gradle.kts
I have extracted some build logic into the plugins:
service-0/build.gradle.kts
plugins {
mytemplate
}
renderTemplate {
template = File()
output = File()
context = getContext()
}
What I would like to do now is to have a dev and prod profile. For that, I might have some utils code:
enum class Profile { DEV, PROD }
val currentProfile: Profile
get() = System.getProperty(PROFILE_PROP).toProfile()
So then I can have some profile specific build logic:
service-0/build.gradle.kts
plugins {
mytemplate
}
renderTemplate {
template = File()
output = File()
context = when(currentProfile) {
DEV -> getDevContext()
PROD -> getProdContext()
}
}
Also, I would like to reuse this profile utils in other subprojects.
As far as I know there is no way to expose code from within precompiled script plugins and the only way to archive this to have a separate project with utity code, create jar / upload to maven local and then add it as a buildscript dependency to all modules, which seems super cumbersome.
Am I missing something? Is there a better way to do this or is this not the way to approach profiles at all?