Can maven upload/publish be made dependent on build tasks' UP-TO-DATE status?

This may be published somewhere that I’m not finding but, well, I’m not finding it. Here’s the scenario:

  • I have a project that generates multiple artifacts * A change in the git repository may not result in changes to all artifacts * Those artifacts that have not changed are properly reporting UP-TO-DATE in their assembly tasks (jar, war, ear, etc) * I only want to upload artifacts to my Nexus repository if they have changed

Using the maven plugin, is there an easy way to accomplish this?

Try something like:

uploadArchives.onlyIf { jar.didWork }

I used this in one of my first gradle builds. turns out it can lead to some unstable behaviour. Imagine your build faild between jar task and uploadarchives (e.g. during testing), but this is fixed in the next build. If that’s the case the jar is never published.