How to depend on a local library with maven

允我心安 提交于 2019-12-25 02:46:13

问题


I have a project contains two sub projects: A. a common library for external api B. a program depends on above library They are inside same directory. How I made B refer to A with maven?


回答1:


Normally you will always share through a maven repository. That is mavens way to ensure a consistent and correct solution and a solution shareable by all developers.

You should search for a public maven repository with project A (e.g. http://search.maven.org or http://mvnrepository.com) and include in your pom

If it does not exist in public (is proprietary in someway or other), consider using an enterprise-wide maven repository such as nexus or artifactory to push to repositories.

Finally, some developers resort to either installing a mvn-local file if you are ever only going to work on an explicit workstation.

If you still prefer a filebased acces, it is possible to define a maven file repository and reference it in your pom. E.g. Heroku use this for bundling extra dependencies into their system.




回答2:


Declare A as dependency in B's pom.xml. Make sure A has valid pom.xml and is deployed to your repository (local/nexus). We do that all the time. Take care to assign SNAPSHOT version if you always want latest to be pulled from repository.



来源:https://stackoverflow.com/questions/25173896/how-to-depend-on-a-local-library-with-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!