问题
- I have multiple eclipse workspaces with maven projects.
- Some projects use the same dependencies in pom.xml but different versions.
- Can I have a single pom.xml on my computer, each workspace/project pom.xml will point to this main pom.xml
- So that i can control the version of the dependencies in the main pom.xml rather than each pom.xml in each workspace/project.
Any suggestions how to set this up will be helpful. Thanks again for checking this.
回答1:
The pattern that you describe is called "Bill of Material".
You create a new maven project (the bill of material) that only consists of a pom with dependency management block. Here you declare all your dependencies and their versions. The packaging should be set to pom.
This bill of material (bom) project is now used as parent of all other projects. When using a dependency, only group id and artifact id is specified, the version tag is ommited. In that way, the version will be taken from the bom and you have one central place to manage the versions of the dependencies.
More details with examples are here (in the lower part of the page) or here.
来源:https://stackoverflow.com/questions/49559662/centralize-pom-dependencies-for-my-desktop