I managed to achieve this using Maven 3.3.9 ... but let me describe my scenario:
I work with a Java infrastructure called Liferay, where there is a tool called Service Builder that can create and deploy services using Maven with the exact structure, as you described:
Service Layer |-pom.xml (version 1.12.0-SNAPSHOT) |-Service Portlet | |-pom.xml (version 1.16.0-SNAPSHOT)<--- |-Service | Artifact dependency | |-pom.xml (version 1.5.0-SNAPSHOT)-----
As you can see, the portlet application module is built with a service dependent dependency, which is a .jar file that contains interfaces, among other things, for the services to work.
By the way, I did this with my project using modules of different versions. I found an interesting article about this practice: Releasing modules of a multi-module project with independent version numbers . You can read the abstract to draw your own conclusions about whether the modules are suitable for versions or not ... but from my point of view, after reading the requirements of the Client, it seems reasonable to me that version control of the modules should be supported by the Maven function, without being too painful for implementation.
Running mvn release:prepare and mvn:perform inside the parent (Service Layer) is the way to go. Maven does the creation and deployment of the release in the following order: 1) the parent pom 2) the dependency of the service 3) the portlet of the service.
Maven took care of the order, and it's nice ... but the service dependency is built on the basis of the portlet source code, and the goal is fulfilled in the parent project: mvn liferay:build-service ... so that the dependency is affected by the portlet application source code (sounds a little crazy) . That was the hard part in my case.
So, how can we get the service dependency created and deployed for the service portlet to use it?
Well, the solution for this was to use the configuration in the maven-release plugin, which allows Maven to run specific goals in the release:perform phase in any of the projects. What I did was add this configuration to the maven-release-plugin declaration in the parent pom.xml (Service Layer):
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5.2</version> <configuration> <goals>clean liferay:build-service deploy</goals> </configuration> </plugin>
And Maven was able to deploy the parent and each of the child modules with our preferred version numbers (you will be asked to enter them).
Generic answer and recommendation: try using the <goals> configuration and run mvn release:prepare and mvn release:perform at the parent level
Parent and modules must be deployed in order.
I hope this inspires someone in a similar situation, at least after 5 years.