This message was deleted.
# plugin-development
s
This message was deleted.
f
Another way I think of is manipulating Task B's
enabled
flag in Task A but that also seems fishy.
aha I was approaching this from the wrong angle. I need to conditionally apply
dependsOn
in the the configuration of Task B. Another episode of me writing things down and through that finding a solution 🙂 Thanks for listening 😉
v
calling task B directly with execute()
This was never supported and always highly problematic and risky and should never be done. If you actually can do this, you should upgrade anyway, as this method is loooong gone for good reasons. The main question is, why would you do a string comparison as a task action? If you really would want to set some state in one task to get it in another one, a shared build service would be the proper way. But task A per-se sounds like it is not really idiomatic to exist at all. 🙂 Unless of course you oversimplified the situation in your description. :-)
f
let me show you what I ended up with for now, maybe that helps to explain my use case
Copy code
tasks.register("publishAll") {
    val version = Version.parse(providers.gradleProperty("version").get())
    val latest = Version.parse(changelog.getLatest().version)
    if (version > latest) {
        println("Found new version $version that is greater than the latest published one $latest, publishing projects.")
        dependsOn(patchChangelog)
        dependsOn(subprojects.map { ":${it.name}:publish" })
    } else {
        println("No new version found, not publishing anything.")
    }
}
the changelog stuff comes from
org.jetbrains.changelog
(I never used
execute
just read about it when looking for solutions for this thing)
v
So if your project is already newer than what you have in the changelog, you publish it? I don't get that logic 😄
f
let me try to explain 🙂 I have a changelog file where we document relevant changes under "unreleased". When the time comes to make a new release, you simply edit the version in
gradle.properties
and push it. The CI pipeline then executes this
publishAll
task, compares the version and if it detects a new one, edits the changelog, publishes the packages and does a git tag (missing).
v
I see. Wouldn't it be simpler to just trigger the build if you push an annotated version tag?
f
yeah I thought about this as well, but one problem is that you have this tag then even if the build fails (you could of course remove it in that case).
v
Hm, I see
You could configure all
PublishToMavenRepository
tasks with an
onlyIf
that does the version check
f
would you consider that better than what I pasted above?
Copy code
tasks.register("publishAll") {
    dependsOn(patchChangelog)
    dependsOn(subprojects.map { ":${it.name}:publish" })
    onlyIf {
        val version = Version.parse(providers.gradleProperty("version").get())
        val latest = Version.parse(changelog.getLatest().version)
        version > latest
    }
}
like this?
I guess that's better because I don't have provider gets in the config block
v
Nah, that would just skip the
publishAll
that does not have any tasks anyway so is skipped always anyway. That does not skip the dependency tasks.
I said "configure all `PublishToMavenRepository`" tasks with that. And then you can also just remoce the
publishAll
task alltogether and just execute
./gradlew patchChangelog publish
.
f
I would also need to configure patchChangelog with that though
v
indeed
If the calculation is considered costly, you can do it once in a shared build service that you then just use in the `onlyIf`s
f
it's not costly, it would just be nice to only do in one place for readability
you don't like the conditional
dependsOn
? 🙂
In any case, it's getting late. Thank you again for your help!
v
conditional
dependsOn
is fine. I don't like too much direct dependencies between tasks of different projects if they can be avoided. 🙂
But you can probably also keep it like that if it works for you. 🙂