Slackbot
04/16/2023, 7:52 AMAdam
04/16/2023, 8:06 AMgradle.properties.
Or if you just want some variable that might come from gradle.properties on one machine, but is set via an environment variable on another machine, then you can use a project property
Can you explain more about what you want to achieve?Sebastian Schuberth
04/16/2023, 8:10 AMbuild.gradle.kts file. When probing for the Git system config, JGit eventually calls out to the system's git CLI, which is incompatible with Gradle's new configuration caching. JGit's behavior can be suppressed by setting the GIT_CONFIG_NOSYSTEM environment variable, and that's what I'd like to do.Adam
04/16/2023, 8:11 AMAdam
04/16/2023, 8:17 AMSebastian Schuberth
04/16/2023, 9:02 AMgetGitSystemConfig return null.Anze Sodja
04/16/2023, 10:12 AMAnze Sodja
04/16/2023, 10:16 AMSebastian Schuberth
04/16/2023, 7:48 PMbuild.gradle.kts file but I'm getting
* What went wrong:
Could not create an instance of type Build_gradle$GitVersionValueSource.
> Class Build_gradle.GitVersionValueSource is a non-static inner class.Sebastian Schuberth
04/16/2023, 7:54 PMrootDir from the outer scope. What do I need to inject as a property to get access to the project?Anze Sodja
04/16/2023, 8:31 PM// Kotlin
abstract class MyValueSource : ValueSource<String, MyValueSource.MyValueSourceParams> {
private val logger = Logging.getLogger(MyValueSource::class.java)
interface MyValueSourceParams : ValueSourceParameters {
val rootDir: DirectoryProperty
}
override fun obtain(): String {
logger.lifecycle("In value source: " + parameters.rootDir.get().asFile.path)
return parameters.rootDir.get().asFile.path
}
}
val provider = providers.of(MyValueSource::class) {
parameters {
rootDir.set(project.rootDir)
}
// or just parameters.rootDir.set(project.rootDir)
}
println(provider.get())Anze Sodja
04/16/2023, 8:54 PMSebastian Schuberth
04/16/2023, 9:20 PMValueSource, I decided to go with the solution of a custom SystemReader as mentioned at https://stackoverflow.com/a/59110721/1127485 instead.Vampire
06/29/2023, 10:03 PMValueSource
to bootstrap JGit if a new Daemon was started
with not missing the system config which the SO answer causes:
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
plugins {
id("org.ajoberstar.grgit.service") version "5.2.0"
}
abstract class JGitBootstrapper : ValueSource<String, JGitBootstrapper.Parameters> {
override fun obtain(): String {
FileRepositoryBuilder()
.setWorkTree(parameters.projectDirectory.get().asFile)
.build()
return ""
}
interface Parameters : ValueSourceParameters {
val projectDirectory: DirectoryProperty
}
}
providers.of(JGitBootstrapper::class) {
parameters {
projectDirectory.set(layout.projectDirectory)
}
}.get()
println(grgitService.service.get().grgit.head().id)
This way the external proess execution at configuration time is properly wrapped in a ValueSource, and it is only done once in the daemon lifetime as it is done as part of a static initialization.
The actual Git operations done at configuration time then cause the accessed files and environment variables to be configuration cache inputs as usual.
So if you execute this snippet two times, the second time nothing is printed.
If you then create a new commit and rerun without other changes, it is rerun and prints again.Vampire
07/01/2023, 2:23 PMVampire
07/01/2023, 2:24 PMVampire
07/01/2023, 2:27 PMValueSource instead, will execute the operation on every build and if changed even twice,
but only the final result is considered an input, so the remaining configuration phase can be skipped more often.
As this dirty-determination for me is then used in processResources to fill in a placeholder in a properties file,
there would be almost no case where the configuration cache could be reused if all files of the project would properly be input.Vampire
07/01/2023, 2:30 PM