How to define common configurations in maven projects

Emerson Cod :

I hope this is the right place and right discussion to start.

What I want

I am looking for a good/the right way to handle multiple maven projects, that share a common configuration, which is in my case

  1. Set the maven-compiler-plugin version with source/target compilation version
  2. Set the maven-source-plugin to attach sources to artifacts
  3. Define local repository server
  4. Define common dependencies (via dependencyManagement and dependencies).

What I did

My first approach was to create a multi module project. But as the modules are actually independant, when it comes to release (so not the same release cycle), it seemed to be more a burden as a gain. I also failed to make it that I can independently work with a submodule in IntelliJ and have for each submodule it's own Jenkins job. For me it was always all or nothgin

The second approach was/is to have seperate projects. This makes coding in IntelliJ simple and Jenkins can have jobs for each project.

But now changes to parent pom, which affects the children, are tedious to delegate as all other projects must adopt to the change to the new parent.

It is doable and might be the way to work with this, but as I am afraid I misuse the parent concept here, I was wondering, whether there is a better way to use common settings in multiple maven projects ?

Thanks for reading and I hope this was understandable

rustyx :

Just create a parent POM with the common settings and keep the rest separate. Publish that POM to the (local) repository separately as a standalone entity with pom packaging (no submodules at this level).

Have a look at the Spring Boot parent POM as an example.

The only change in your projects would then be to use your new POM as the parent POM.

<project ... >
  <parent>
      <groupId>my-group</groupId>
      <artifactId>my-parent</artifactId>
      <version>1</version>
  </parent>
  ...

Note however that it is generally not a good idea to hardcode dependencies in the parent POM (defining versions via dependencyManagement is OK, but let each project specify explicitly which dependency it actually needs).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=91597&siteId=1