How to release a multi-mode Maven project with cross-project dependencies?

Let's say we have a three-layer project. DB, Business, Web and pom aggregation.

Project |-DB | |-pom.xml |-Business | |-pom.xml |-pom.xml 

All modules must be released and branched together, so the aggregator of the aggregate is configured to assign the same version to all submodules. We have the following versions:

 DB-0.1-SNAPSHOT Business-0.1-SNAPSHOT which depends on DB-0.1-SNAPSHOT Web-0.1-SNAPSHOT which depends on Business-0.1-SNAPSHOT 

When executing release:prepare all versions are updated to 0.1, but they are preparing for failure, because there is no DB-0.1 dependency yet.

One solution is to create different projects for each module and release them one by one using the versions:use-releases plugin to update the dependency on 0.1

But I do not like this idea, because it requires a lot of settings and scripts. Therefore, I prefer to use aggregation and release all modules with one command, but the problem is that, as I wrote above, when the release plugin tries to build Business-0.1 , DB-0.1 is not yet in the repository.

Is there a way to manage these cross-project dependencies?

Thanks.

UPD:

even setting a goal fails.

  • DB Build - OK (there is no snapshot or release version in any repository)
  • Business crash (DB-0.1-SNAPSHOT not found in the repository, but it shouldn't even be there!)

I am using maven 3.0.2 and release the plugin 2.1

+4
source share
3 answers

your project should only determine the version in the parent (project) only once. And let all the other modules have a parent relationship. This means that you do not have aggregation. Instead, you create a multi-module assembly.

 Project |-pom.xml (version 0.1-SNAPSHOT) |-DB | |-pom.xml (parent: ..) |-Business | |-pom.xml (parent:..) 

This will solve your problem (maybe you can take a look here as an example ).

+2
source

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.

0
source

For a project with multiple modules, when it does not work for the dependency of the child snapshot, try this release: clean release: prepare release: run -DignoreSnapshots = true

Hope this helps.

0
source

Source: https://habr.com/ru/post/1341964/


All Articles