简体   繁体   中英

How to share commons code between different projects?

I'd like to have 2 different projects: one connecting to a webservice, and another project handling imports.

Both projects will be running for the same final application, but should run on a different server each. Also each project should be able to be released independently (eg if I fix a bug on the importer, I have to release it without reference to the webservice project).

The projects should share some code, eg domain classes. Which maven structure should I use for this purpose? 3 independent projects whereas the commons is installed to the local maven repo and used as dependency by the others?

Or is it somehow possible to directly resolve the commons project from eclipse workspace without having to install it?

svn/Webservice/pom.xml
svn/Cache-Importer/pom.xml
svn/Commons/pom.xml //used by both projects and contains eg shared domain code

I would recommend, as you guessed, the three independent projects model. The Webservice and Cache-Importer projects will depend on the Commons. Having them as separate projects allows you to have different lifecycles for these projects and you can release one, but not the other.

If you want to put them in the same aggregator, this would tie you to having them all released under the same version and some of the modules might not need a version bump at the time. Therefore, in my opinion, this would be a better approach.

If you would like to build them together, but would also like to have them as independent modules, you could create a fourth project which has them defined as <modules/> in the pom.xml . You will need to setup svn:externals (as explained here ) and basically link the paths of the modules to this project. This way you'll be able to check them out altogether and build them, while you'll also be able to release them independently as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM