Slackbot
06/15/2022, 9:28 PMChris Lee
06/15/2022, 9:29 PMproject.version.toString()
) multiple times, incurring latency?Javi
06/15/2022, 9:35 PMChris Lee
06/15/2022, 9:36 PMJavi
06/15/2022, 9:36 PMChris Lee
06/15/2022, 9:37 PMJavi
06/15/2022, 9:37 PMChris Lee
06/15/2022, 9:38 PMJavi
06/15/2022, 9:42 PMprivate fun Project.configureLazyVersion() {
version = LazyVersion(VersionValueSource.register(this))
// Some third party plugin breaks lazy configuration by calling `project.version`
// too early based on plugins order, applying the calculated version in
// `afterEvaluate` fix it
afterEvaluate { it.version = LazyVersion(VersionValueSource.register(this)) }
}
Javi
06/15/2022, 9:43 PMpublic companion object {
internal fun register(project: Project): Provider<String> =
with(project) {
providers
.of(VersionValueSource::class) {
it.parameters.gitDir.set(layout.dir(provider { gitDir }))
it.parameters.tagPrefixProperty.set(tagPrefixProperty)
it.parameters.projectTagPrefix.set(semverExtension.tagPrefix)
it.parameters.stageProperty.set(stageProperty)
it.parameters.scopeProperty.set(scopeProperty)
it.parameters.creatingSemverTag.set(isCreatingSemverTag)
it.parameters.checkClean.set(checkCleanProperty)
}
.forUseAtConfigurationTime()
}
}
Chris Lee
06/15/2022, 9:44 PMJavi
06/15/2022, 9:45 PMChris Lee
06/15/2022, 9:46 PMJavi
06/15/2022, 9:47 PMChris Lee
06/15/2022, 9:47 PMJavi
06/15/2022, 9:51 PMJavi
06/15/2022, 10:40 PMpublic class LazyVersion(internal val version: Provider<String>) {
private var cachedVersion: String? = null
override fun toString(): String {
if (cachedVersion != null) cachedVersion = version.get()
return cachedVersion ?: version.get()
}
}
Chris Lee
06/15/2022, 10:54 PMJavi
06/15/2022, 10:55 PMJavi
06/15/2022, 11:26 PMChris Lee
06/15/2022, 11:28 PMif (cachedVersion == null) cachedVersion = version.get()
return cachedVersion ?: version.get()
Chris Lee
06/15/2022, 11:28 PMif (cachedVersion == null) cachedVersion = version.get()
return cachedVersion
Javi
06/15/2022, 11:30 PMJavi
06/15/2022, 11:31 PM?: version.get()
, cachedVersion is still nullable, the only way to avoid it is using letJavi
06/15/2022, 11:31 PMval
Chris Lee
06/15/2022, 11:31 PM!!
as you know it can’t ever be null.Javi
06/15/2022, 11:33 PMChris Lee
06/15/2022, 11:34 PMChris Lee
06/15/2022, 11:35 PMval cachedVersion = "1.2.0"
, as a test, avoiding calling the provider.Javi
06/15/2022, 11:36 PMJavi
06/15/2022, 11:37 PMJavi
06/15/2022, 11:38 PMChris Lee
06/15/2022, 11:38 PMJavi
06/15/2022, 11:39 PMJavi
06/15/2022, 11:47 PMJavi
06/15/2022, 11:51 PMLazyVersion
is not enough to fix this issue, maybe the instance is recreated constantly?Chris Lee
06/15/2022, 11:52 PMJavi
06/15/2022, 11:52 PMJavi
06/15/2022, 11:58 PMJavi
06/16/2022, 12:05 AMChris Lee
06/16/2022, 12:12 AMproject.version = project.rootProject.version
Javi
06/16/2022, 12:18 AMv
and a subproject one w
, with different versions.Javi
06/16/2022, 12:19 AMJavi
06/16/2022, 12:30 AMTIME: 2509
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
TIME: 0
Vampire
06/16/2022, 1:10 AMJavi
06/16/2022, 8:07 AMValueSource
has no the same APIs than the tasks where you can pass whatever you want as varargs
.Javi
06/16/2022, 10:06 AMProvider<String>
directly, so I will have to pass everything into it.
Should be great I can somehow teach Gradle how a third party class can be serialized or something soChris Lee
06/16/2022, 1:29 PMJavi
06/16/2022, 1:45 PMChris Lee
06/16/2022, 1:52 PMJavi
06/16/2022, 1:54 PMJavi
06/16/2022, 1:58 PMJavi
06/16/2022, 2:08 PMTIME: 1
TIME: 0
TIME: 0
...
Javi
06/16/2022, 2:09 PMChris Lee
06/16/2022, 2:09 PMJavi
06/16/2022, 2:14 PMJavi
06/16/2022, 2:14 PMJavi
06/16/2022, 2:16 PMBUILD SUCCESSFUL in 1m 41s
Javi
06/16/2022, 2:17 PMJavi
06/16/2022, 2:17 PMget()
to the build service in configurationJavi
06/16/2022, 2:18 PMChris Lee
06/16/2022, 2:20 PMgitTagBuildService.map { it.git // … call version calculation}
to get a Provider<String> without exposing git
.Chris Lee
06/16/2022, 2:23 PMJavi
06/16/2022, 2:24 PMChris Lee
06/16/2022, 2:26 PMJavi
06/16/2022, 2:28 PMproviders.of
so it should be lazy, but it is still taking 1m 33.358s
.
I am going to retry with the old version of the plugin againJavi
06/16/2022, 2:30 PMpassing the Project around is a code smell, should look at alternate designsI think in that register I can pass objects or providers and not the entire git dir
Javi
06/16/2022, 2:33 PMBUILD SUCCESSFUL in 12s
129 actionable tasks: 129 executed
Javi
06/16/2022, 2:33 PMChris Lee
06/16/2022, 2:34 PMJavi
06/16/2022, 2:42 PMChris Lee
06/16/2022, 2:43 PMJavi
06/16/2022, 2:46 PMChris Lee
06/16/2022, 2:47 PMJavi
06/16/2022, 2:48 PMJavi
06/16/2022, 2:49 PMChris Lee
06/16/2022, 2:49 PMChris Lee
06/16/2022, 2:50 PMChris Lee
06/16/2022, 2:51 PMJavi
06/16/2022, 2:54 PMJavi
06/16/2022, 2:55 PMJavi
06/16/2022, 2:55 PMChris Lee
06/16/2022, 2:56 PMgetVersion( dir : File ) : String
; inside there do all the work.
No need for ValueSource as the build service is the provider.
invoke via `buildService.map { it.getVersion( project.projectDir ) }`to get a Provider<String>.Javi
06/16/2022, 3:00 PMChris Lee
06/16/2022, 3:01 PMJavi
06/16/2022, 3:01 PM.git
dir as an input in the extension, but the config cache was not invalidated even when it was changingJavi
06/16/2022, 3:05 PMJavi
06/16/2022, 3:11 PMJavi
06/16/2022, 5:01 PMBUILD SUCCESSFUL in 9s
156 actionable tasks: 156 executed
Vampire
06/16/2022, 5:17 PMJavi
06/16/2022, 5:22 PMVampire
06/16/2022, 5:22 PMJavi
06/16/2022, 5:23 PMJavi
06/16/2022, 5:25 PMJavi
06/16/2022, 5:25 PM