Publish to Maven Local: how to use finalizeBy for associated task

I have library code that I publish to Maven local, using:

publishing {
    publications {
        maven(MavenPublication) {
            groupId = 'com.mystuff'
            artifactId = 'mylib'
            version = version


I also have a separate task that I want to always run immediately after publishing.

Regular Gradle tasks have a ‘finalizedBy’ option that will auto-run the finalizedBy task after the first task runs.

Is there a way to do something like finalizedBy for this publishing task?

The publishing task is just a regular task. Is you really want to do it, just do it.

Or did you mean the task called “publishing”? If so, there is no such task. You are configuring the publishing extension there, not a task.

The code I posted above is it. I believe I copied it from somewhere online to do Maven local publishing.

If it’s not possible to add a finalizedBy, or another workaround, I’ll just have to manually run it each time.

As I said, you are not configuring tasks there.
You are configuring an extension.
And the according plugin will register multiple tasks out of this configuration.
And for whatever task is suitable for your use-case, you can register a finalizedBy task.