Multi-project builds and publishing to Maven

I have two projects in a multi-project setup, A and B, each producing a JAR that I want to upload to Maven.
B depends on A:

dependencies {
  compile project(':A')

However, eventually, in B’s POM file I would like the dependency to appear as A’s Maven coordinates.
In practice, my multi-project is more involved than this example and I’m seeking a mechanical way to do those local-project -> their Maven coordinates translation. I cannot directly depend on the Maven coordinates of A from B, since A has not yet been published when B is built, so B’s compilation will fail.


Does anyone know the answer? This must be a pretty common case I imagine.

This should already be happening so long as you are publishing these projects as part of the same multi-project build. The Maven coordinates simply get mapped to

You shouldn’t be depending on the Maven artifact, you should continue to use a project dependency as in your example above.

Take a look at the chapter on Multi-project Builds in the User Guide. The use case you are describing is indeed common and definitely supported. If you encountering problems post the errors you are getting and any snippets from your build scripts that you can.

I have verified this to work. My confusion resulted from assuming the mapping depends on the pom.project… settings as opposed to the project… settings, which only serve as defaults for the former. So I have a working solution for now, although arguably the plugin’s behavior is unclean.