Using publish with mustRunAfter

Hi, I need publishing to be performed after some other task. I tried the following approaches but both do not work:

publish.mustRunAfter(otherTask)
publishMavenJavaPublicationToMavenRepository.mustRunAfter(otherTask)

The first approach does nothing, while the second returns the following error:

Could not find property 'publishMavenJavaPublicationToMavenRepository' on project ':some-project'.

I think I understand why it happens, but it is not intuitive and I dont know how to make it work.