Slackbot
06/01/2022, 2:45 PMChris Lee
06/01/2022, 2:47 PMChris Lee
06/01/2022, 2:48 PMJavi
06/01/2022, 2:53 PMJavi
06/01/2022, 3:08 PMhelp
) even after trying to add the previous defaultTasks
+ myNewTask
. Is it possible to keep them?Chris Lee
06/01/2022, 3:10 PM./gradlew help
Javi
06/01/2022, 3:11 PMJavi
06/01/2022, 3:11 PMChris Lee
06/01/2022, 3:13 PMtasks.named("build") {
dependsOn(myTask)
}
Javi
06/01/2022, 3:15 PMJavi
06/01/2022, 3:15 PMChris Lee
06/01/2022, 3:17 PMtasks.configureEach {
dependsOn(myTask)
}
…to run your task before any others. Presumably the version is only required if other tasks are run to consume it.
This is bit fragile - if tasks are consuming the version, they should have a inferred dependency on the task that generates the version.Javi
06/01/2022, 3:55 PMChris Lee
06/01/2022, 3:56 PMservice.map { it.resolveVersion() }
(a provider) provided to tasks to pull in the version.Javi
06/01/2022, 5:01 PMtoString
so I am not sure how to fix this issue with a providerChris Lee
06/01/2022, 5:13 PMJavi
06/01/2022, 5:27 PMChris Lee
06/01/2022, 5:27 PMephemient
06/01/2022, 5:28 PMversion = object {
override fun toString() = computeVersion()
}
might workChris Lee
06/01/2022, 5:29 PMJavi
06/01/2022, 5:32 PMProperty<String>
and toString
calls to prop.get()
. Is should be the same that your statement @ephemient?ephemient
06/01/2022, 5:44 PM.get()
is called only once instead of re-fetched (if it's the result of a provider, it'll get evaluated every time), and ensure that .set
isn't called after (.finalizeValue
will do both), but yesJavi
06/01/2022, 5:56 PMunspecified
when publishingChris Lee
06/01/2022, 5:57 PMunspecified
. A simple test would be
version = object {
override fun toString() = "MyVersion"
}
…to confirm that structure, then add the dynamic resolution of version.Javi
06/01/2022, 6:03 PMChris Lee
06/01/2022, 6:03 PMJavi
06/01/2022, 6:03 PMJavi
06/01/2022, 6:03 PMChris Lee
06/01/2022, 6:03 PMJavi
06/05/2022, 4:49 PMJavi
06/12/2022, 5:16 PMyou might want to ensureAt same time I am not only passing the calculated version, a tag prefix too, which is available in the my plugin extension.is called only once instead of re-fetched (if it's the result of a provider, it'll get evaluated every time), and ensure that.get()
isn't called after (.set
will do both), but yes.finalizeValue
public class LazyVersion
private constructor(
projectTagPrefix: Provider<String>,
calculatedVersion: Provider<String>,
) {
public val tagPrefix: Provider<String> = projectTagPrefix
public val version: Provider<String> = calculatedVersion
public val semver: Version?
get() = Version.safe(version.get()).getOrNull()
public val semverWithTagPrefix: String?
get() = semver?.let { semanticVersion -> "${tagPrefix.get()}$semanticVersion" }
override fun toString(): String = "${tagPrefix.get()}${version.get()}"
public companion object {
internal operator fun invoke(project: Project): LazyVersion =
with(project) {
LazyVersion(
projectTagPrefix = semverExtension.tagPrefix,
calculatedVersion =
provider {
val projectTagPrefix = semverExtension.tagPrefix.get()
val isSamePrefix = tagPrefixProperty == projectTagPrefix
val version =
git.calculatedVersion(
tagPrefix = projectTagPrefix,
stageProperty = stageProperty.takeIf { isSamePrefix },
scopeProperty = scopeProperty.takeIf { isSamePrefix },
isCreatingSemverTag =
isCreatingSemverTag.takeIf { isSamePrefix } ?: false,
mockDate = mockDateProperty,
checkClean = checkCleanProperty,
)
checkVersionIsHigherOrSame(
version,
git.lastVersionInCurrentBranch(semverExtension.tagPrefix.get())
)
version
}
)
}
}
}