https://github.com/eitco/manage-plugin-dependencies-maven-extension
a maven extension making dependency management affect dependencies that are added to plugins
https://github.com/eitco/manage-plugin-dependencies-maven-extension
Last synced: about 1 year ago
JSON representation
a maven extension making dependency management affect dependencies that are added to plugins
- Host: GitHub
- URL: https://github.com/eitco/manage-plugin-dependencies-maven-extension
- Owner: eitco
- License: mit
- Created: 2024-06-21T15:00:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-28T08:17:11.000Z (almost 2 years ago)
- Last Synced: 2024-08-28T09:26:00.072Z (almost 2 years ago)
- Language: Java
- Size: 43 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/license/mit)
[](https://github.com/eitco/manage-plugin-dependencies-maven-extension/actions/workflows/deploy.yaml)
[](https://central.sonatype.com/artifact/de.eitco.cicd/manage-plugin-dependencies-maven-extension)
# maven core extension to manage dependencies in the plugins section
This maven extension makes dependency management affect dependencies in the plugin section. There has been an
[issue](https://issues.apache.org/jira/browse/MNG-2496) about this for a long time, that only recently
was closed - not to be fixed.
It turns out however, that implementing a maven extension doing exactly this is pretty straightforward.
# use case
Assume a pom.xml with the following content:
````xml
...
42.7.3
org.postgresql
postgresql
${postgres.version}
org.liquibase
liquibase-maven-plugin
...
org.postgresql
postgresql
${postgres.version}
org.jooq
jooq-codegen-maven
...
org.postgresql
postgresql
${postgres.version}
````
Of course one wants to make sure that both plugins use the jdbc client in the same version (1). Which should be
the same as the jdbc client the application itself uses (2).
In this example this is achieved using a property, but what if one needs to share this version in a way where
properties cannot be used. For example, what if the jdbc drivers version is managed in the dependency management
of an imported pom:
````xml
...
my.organisation
organisation-bom
1.0.0
bom
import
org.postgresql
postgresql
org.liquibase
liquibase-maven-plugin
...
org.postgresql
postgresql
org.jooq
jooq-codegen-maven
...
org.postgresql
postgresql
````
Now, the version is managed in a bill of materials which is imported (1), so that the version of the applications
dependency may be omitted (2), the versions of the plugins dependencies (3), however are now unspecified. This would
make maven fail the build while parsing the project. One could - of course - specify a property again, but it would
not be guarantied that it is the same that is used in the bill of materials pom.
This extension fixes that. It does inject itself in mavens process of reading a project and adds the correct managed dependency
versions to dependencies declared in the plugin section that have no versions specified.
# usage
To activate the extension simply add a file `.mvn/extensions.xml` to the root of your project with the following content:
````xml
de.eitco.cicd
manage-plugin-dependencies-maven-extension
0.0.2
````
> 📘 There are other ways to [activate core extensions](https://maven.apache.org/guides/mini/guide-using-extensions.html#core-extension).
Adding this file will enable maven to read (and execute) the example above - using the postgres clients version that
is managed in the imported pom.
> 📘 The [integration tests](src/it) provide some example usages
> ⚠️ Note that, when importing a bill-of-materials `pom.xml` from the same build reactor, you need to make
> sure that the imported `bill-of-materials` is ordered before the importing `pom.xml` in the build reactor.