2

We are using Maven to define and manage our dependencies between our microservices. Here is an example:

Microservice 1

<artifactId>ms-1</artifactId>
<version>0.25.04-SNAPSHOT</version>
<dependencies>
    <dependency>
        <artifactId>ms-2</artifactId>
        <version>0.25.00-SNAPSHOT</version>
    </dependency>
</dependencies>

Microservice 2

<artifactId>ms-2</artifactId>
<version>0.25.00-SNAPSHOT</version>
<dependencies>
    <dependency>
        <artifactId>ms-3</artifactId>
        <version>0.28.00-SNAPSHOT</version>
    </dependency>
</dependencies>

The problem is that the release phase is taking a lot of time and is fully manual:

  1. perform mvn:release for the first microservice (removes -SNAPSHOT)
  2. change the version in pom.xml of the dependency
  3. perform mvn:release for the second microservice (removes -SNAPSHOT)
  4. and so on (actually on 15 microservices...)

I'm wondering if there is any automatized way to perform this release (in cascade)?

Thanks

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
frinux
  • 2,052
  • 6
  • 26
  • 47

1 Answers1

3

A Maven project is not in charge of managing the versions of its dependencies. It's the project that builds a dependency artifact that's responsible for its version.

In your case you could create a (pseudo-)aggregator project that includes all your microservices as sub-modules:

<modules>
    <module>../ms-1</module>
    <module>../ms-2</module>
    <module>../ms-3</module>
    <module>../...</module>
    <module>../ms-15</module>
</modules>

Assuming that your microservice projects are siblings to each other like:

+- (pseudo-)aggregator
|  +- pom.xml
+- ms-1
|  +- pom.xml
+- ms-2
|  +- pom.xml
+- ms-3
|  +- pom.xml
+- ms-...
|  +- pom.xml
+- ms-15
   +- pom.xml

If they are not adapt the relative <module>s paths accordingly.

Such you are asked for the release versions of all of the projects (default is current <version> minus -SNAPSHOT, to be confirmed by just Enter) during a .../(pseudo-)aggregator $ mvnrelease:prepare, which also updates your <dependencies>/<dependency>/<version>s accordingly.

Or you can perform a non-interactive release with -B | --batch-mode which uses the defaults without asking.

And finally an amendment:

release is not a phase of Maven's build lifecycles. It's the shortcut for the maven-release-plugin that has various goals.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • That's interesting, I didn't know about Maven aggregator. Let me rephrase to check if I'm right. You suggest I create a dedicated POM project, which defines all my microservices as module, and then call the maven goals to perform a release? – frinux Jun 27 '16 at 16:04
  • @frinux That's right. See [POM Reference, Aggregation](https://maven.apache.org/pom.html#Aggregation) and [Maven: The Complete Reference, 3.6.2. Multi-module vs. Inheritance](http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom-best-practice.html#pom-relationships-sect-multi-vs-inherit) for basic information. See also [this answer](http://stackoverflow.com/a/30953905/1744774) for how phases, plugins, goals, etc. work together. – Gerold Broser Jun 27 '16 at 16:17
  • There is a detail I forgot to mention: the microservices consume each other through a JAR (HTTP client) which is generated, but doesn't exist at the moment of the maven release. It seems it is impossible to declare a module if it doesn't exist at the build time, am I wrong? – frinux Jun 28 '16 at 07:45
  • I guess I'm hitting a limit of our architecture : we are coupling microservices between them when we generate API clients. Maybe the right way is to use an AMQP? – frinux Jun 28 '16 at 07:53
  • @frinux You're right, you can't declare a module that doesn't exist. But you can create a placeholder module that contains just a `pom.xml` with ``, ``, ``as sole content for the time being. – Gerold Broser Jun 28 '16 at 09:52
  • 1
    Thanks I managed by creating a real project for each microservice, and to declare them all modules of a pseudo-project "release" which can now perform release for each microservices. – frinux Jun 29 '16 at 14:17