How to use Maven 3 mixins?

You can use open-source plugins to introduce mixin into your pom.

There are several plugins which tackle the hierarchy complexity in form of mixin. One of them is designed to solved the hierarchy in plugin / plugin management section.

It reads all the imported POM files and merge them to the POM file in the same manner Maven calculates the effective-pom. The plugin merges only the build, properties and profiles sections and does not merge any other elements of the pom such as dependencies, repositories, etc…

In the below snippet, the artifact sample-mixin will consume the plugin management configuration as defined in the sample-mixin pom file. No need to inherit any parent /base pom for this..

<plugin>
  <groupId>com.github.odavid.maven.plugins</groupId>
  <artifactId>mixin-maven-plugin</artifactId>
  <version>0.1-alpha-23</version>
  <extensions>true</extensions>
  <configuration>
    <mixins>
      <mixin>
        <groupId>mixin-example</groupId>
        <artifactId>sample-mixin</artifactId>
        <version>${project.version}</version>
      </mixin>
    </mixins>
  </configuration>
</plugin>

For further reading, check it out: http://rethinkingswd.blogspot.co.il/2014/09/mixin-maven-plugin-reusable-project.html


Jesse Glick pointed to Maven issue 5102, so I just wanted to mention that the most recent comment there (2 Oct 2012) links to a new maven plugin that offers mixin behavior: maven-tiles. This seems to be the best option until mixin support is actually baked into Maven (something that has been delayed for several years now).

Edit 2015-Jan: tknerr pointed out that this issue has been flagged for review for Maven 4 inclusion. The Maven devs seem to believe that POM format changes are required to support this feature correctly. (As a long-time Maven user, I'm not surprised by this.)


In a comment to this answer, Brett Porter wrote:

Maven 3.0 doesn't offer mixins yet, however. – Brett Porter Feb 16 at 8:18

And AFAIK, mixins still aren't there.