-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add support for POM mixins #1209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a810482 to
f97c405
Compare
81f4422 to
211e27a
Compare
1570e7f to
4c87f2a
Compare
c2b6ec7 to
e4cd448
Compare
| <mixins> | ||
| <mixin> | ||
| <groupId>org.apache.maven.its.mng5102</groupId> | ||
| <artifactId>mixin-2</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this take a classifier? One of the early issues we identified with tiles - which is why we have a pom.xml and a tile.xml - is for publishing to a repo.
The pom.xml would have release plugin information, which tne tile/mixin wouldn't want.
I like what I'm seeing here, and it looks like it should support my own needs - will try find some time to pull/build this locally and give it a renewed test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's now supported !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great news. I looked at the tests quickly and it seemed like the mixins there only contains properties.
What can be included (or not included) in the mixins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mixins are merged in their declaration order as if they were parents, so there are no restrictions at this point. I haven't given much thought if there should be yet...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@talios Our organization use your Maven Tiles (thank you!). Trying to think if there is something in Maven Tiles that this current implementation of Maven Mixins does not support. With Maven Tiles we have issues with profiles (the are active but Maven does not alwats acknowledge them) and properties (properties aren't propagated).
From what Guillaume wrote it seems as if mixins, currently not having any restrictions, might function even better that Maven Tiles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimisola Depending on how this works in practise - and @gnodet may be able to quickly confirm, one big thing that users of tiles seem to love (which is something I'd gladly give up as I don't overlike it) - is having mixins, that contain mixins.
Tiles also (by default) disallows dependencies (unlocked via the code smells configuration) - but it's often useful to include runtime dependencies to match plugins.
Say an antlr mixin might declared the antlr runtime dep, AND the plugin config.
One thing I don't see here (and also only cause I've not yet had a running version work yet) is logging of mixins being pulled in. That's quite handy for debugging, as is our default behavior of rewriting the execution ids to be prefixed by the mixin.
The rewriting of execution ids could easily just be done IN the mixin, with descriptive ids to begin with tho.
Properties aren't propagated? AFAIK they are as we use them often, the issue we have (which is possible more to Model inheritance) is if a tile references a property, but doesn't declare it a default value THEN it doesn't seem to work.
But having a property defined at the mixin/tile level, and overridden in the top level pom works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is of interest for @gnodet but here is our Maven Tiles setup.
We use tiles and composites where are used to group tiles.
Hence, we have a need for including mixins in mixins for us to be able to group mixins into composites.
Parent Tile
- maven-tiles-parent which is used to set the Maven Tiles version for all tiles (won't be needed with Maven Mixins)
Tiles:
- common-tile
- java-17-tile
- java-21-tile
- lfv-development-environment-tile
- lint-tile
- maven-core-versions-tile
- openapi-tile
- opentelemetry-tile
- reqstool-tile
- soap-tile
- spring-boot-amqp-tile
- spring-boot-application-tile
- spring-boot-camel-tile
- spring-boot-mvc-tile
- spring-boot-oauth-tile
- spring-boot-redis-tile
- spring-boot-tile
- spring-boot-vault-tile
- sysdev-common-tile
- test-compile-tile
@talios As for the properties issue (our use case seem to be different), with respect for this PR we refer to this new ticket in Maven Tiles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimisola I saw that ticket, I see what you mean - I always propagate UP into the tile (so overrides in the project).
I've never really been a fan of composites (which are usually dependencies) as BOM imports already exist - composites just remove the need to declare each dependency in each module - which, in our application which is OSGi based can cause issues if we're just adding deps unseen - I guess it also depends on how often you churn releases of tiles, or dependencies ( we use an additional tool I wrote for $work that handles version ranges/lock files) to track and check that.
Out of interesting - do you tiles include dependencies, or just plugins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@talios Both dependencies and plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally got around to testing this (it's been a hectic fortnight). From a fresh archetype:generated project, and updating the model version and XML preamble, adding the following maven tile "mixin":
<mixins>
<mixin>
<groupId>com.smxemail.tiles</groupId>
<artifactId>com.smxemail.tiles.enforcements</artifactId>
<version>4.0.176</version>
<extension>xml</extension>
</mixin>
</mixins>Everything seemed to work as expected!
Compared to the tiles config:
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>2.40</version>
<extensions>true</extensions>
<configuration>
<tiles>
<tile>com.smxemail.tiles:com.smxemail.tiles.enforcements:[4.0.176]</tile>
</tiles>
</configuration>
</plugin>I long for the day when we can have some more concise GAV specifications in Maven, but this is looking good as a transition.
The tile does transclude another tile, which obviously doesn't work here. I will craft one with its own <mixin> element and do some further testing.
|
One challenge we have with Maven Tiles is that plugin configurations for the same plugin will overwrite each other. How is this handled with mixins? |
They use the same mechanism as parents, so it will be like if one plugin definition is in the parent and the other one in the grand-parent. They end up being merged. The order will have to be clearly specified though. |
When you say merged - in what way? A (parent): B (child) What would be the outcome of the above?
|
Maven identifies plugins by their groupId and artifactId. Since both parent and child define the same plugin, their configurations are merged. Configuration Merging:For non-conflicting elements (elements present in one POM but not the other), Maven includes both elements in the final configuration. Non-conflicting elements:Parent has a, which is not present in the child. This element is included in the final configuration. Conflicting elements:Both parent and child define . The parent has a, and the child has b. Resulting Configuration:The merged configuration for the plugin in the child project will include: Final Outcome <build>
<plugins>
<plugin>
<groupId>plugin</groupId>
<artifactId>plugin</artifactId>
<configuration>
<a>a</a>
<b>b</b>
<c>b</c>
</configuration>
</plugin>
</plugins>
</build>NotesIf you want to append configurations (e.g., combine <configuration combine.children="append">
<b>b</b>
<c>b</c>
</configuration>This would require a more complex structure for <plugin>
<groupId>plugin</groupId>
<artifactId>plugin</artifactId>
<inherited>false</inherited>
<configuration>
<b>b</b>
<c>b</c>
</configuration>
</plugin>This would result in only |
|
@gnodet Thank you for the very thorough description with examples. Been using Maven for decades (literally!) and I just realized that I've never seen the advanced configuration inheritance with Really looking forward to mixins in Maven 4. |
444061b to
9546305
Compare
|
Resolve #6814 |
|
@gnodet Will this be included in Maven 4 (4.0.0-rc and final)? |
We're trying to freeze 4.0, so it's scheduled for 4.1. |
Ok. That was unfortunate but totally understandable. Good luck with 4.0.0! |
16ab167 to
014b2cc
Compare
This commit implements Maven Mixins, a powerful mechanism for sharing common POM configuration across multiple projects without the limitations of traditional inheritance. Key features: - Compose project configuration from multiple sources - Overcome single inheritance limitation - Reduce configuration duplication - Enable better separation of concerns Changes include: - New model version 4.2.0 support for mixins - Mixin and mixinManagement elements in POM model - Mixin resolution and composition logic - Integration with existing inheritance system - Comprehensive documentation and examples - Maven 3 compatibility fixes for maven.config The implementation allows projects to declare mixins that are resolved and merged in order, with later mixins overriding earlier ones, and the current POM having final precedence.
|
@gnodet Please assign appropriate label to PR according to the type of change. |
|
@gnodet Is there pre-build of Maven 4.1 somewhere that can be used to test Maven Mixins? When do you think it is likely that 4.1 will be released? |
Needs to be rebased on top of #2475
Maven POM Mixins: Enhancing Project Composition
Overview
Maven 4.1.0 introduces POM Mixins, a powerful new feature that allows for more flexible and modular project composition. Mixins enable you to extract common configurations into reusable components that can be included in your projects, promoting better organization and reducing duplication across your build configurations.
What are Mixins?
Mixins are reusable POM fragments that can be included in your project, similar to parent POMs but with more flexibility. Unlike parent POMs which establish a strict hierarchy, mixins allow for composition from multiple sources without inheritance constraints. This enables a more modular approach to build configuration.
Key Benefits
Usage Examples
Including a Mixin by Path
Mixins can be included from the file system using a relative path:
Including a Mixin by GAV Coordinates
Mixins can also be retrieved from repositories using standard Maven coordinates:
Using Mixins with Classifiers
For more specialized configurations, mixins can be referenced with classifiers:
Compatibility
Mixins are only available in Maven 4.1.0 and later, corresponding to modelVersion 4.2.0 or higher. Projects using mixins must specify
<modelVersion>4.2.0</modelVersion>in their POM.Implementation Details
The mixins feature extends the Maven model by adding a new
<mixins>element that can contain multiple<mixin>declarations. Each mixin can be specified either by a relative path or by GAV coordinates, optionally with a classifier.When Maven processes a project with mixins, it resolves each mixin, validates it, and merges its contents into the project model according to well-defined merging rules, similar to how parent POMs are processed but with important differences in precedence and inheritance behavior.