Niels Doucet
04/16/2025, 12:29 PMextraProperties
abstraction?Vampire
04/16/2025, 12:35 PMextraProperties
, as you should always feel dirty when using it. 😄
How to best solve it might depend on the details of the situation. Do you maybe have some MCVE one could look at that demonstrates what you try to do or how you use the extra properties?Niels Doucet
04/16/2025, 12:38 PMextraProperties
(yet).Niels Doucet
04/16/2025, 12:40 PMVampire
04/16/2025, 12:41 PMPut a file calledSo can't you simply make sure the thing needed commonly is done in an init script coming first?in theyourfilename.init.gradle(.kts)
directory. Entries will be evaluated in alphabetic order.$_GRADLE_HOME_/init.d/
Niels Doucet
04/16/2025, 12:42 PMVampire
04/16/2025, 12:44 PMinitscript
?Niels Doucet
04/16/2025, 12:46 PMinitscript
🤦
For reference: the logic we're executing
val startParam = gradle.startParameter as org.gradle.api.internal.StartParameterInternal
val environ = org.gradle.internal.cc.impl.services.DefaultEnvironment()
val gradlePropsLoader = org.gradle.initialization.DefaultGradlePropertiesLoader(startParam, environ)
val projPropsLoader = org.gradle.initialization.properties.DefaultProjectPropertiesLoader(startParam, environ)
val propsController =
org.gradle.initialization.DefaultGradlePropertiesController(gradlePropsLoader, { _ -> }, projPropsLoader)
propsController.loadGradlePropertiesFrom(startParam.currentDir, false)
val props = propsController.gradleProperties
val usr = props.find("<usernameProp>") as String
val psw = props.find("<passwordProp>") as String
repositories {
maven {
url = uri("<repo uri>")
credentials {
username = usr
password = psw
}
}
}
Vampire
04/16/2025, 12:46 PMbuildscript
blocks in build scripts and settings scripts, this is evaluated up-front separately to find the dependencies that are needed to execute the init script.
Maybe you could leverage a legacy script plugin by using apply from
within the initscript
to apply the one with the common logic, but I have no idea whether that will work.ephemient
04/16/2025, 2:33 PMVampire
04/16/2025, 3:49 PMinitscript { repositories { ... } }
declaration among the init scripts