How to include a maven module outside of the project context?

后端 未结 2 889
谎友^
谎友^ 2021-01-19 03:25

I\'d like to have a module in some kind of global project directory, so that I can include that module in all other projects that use that common code.

But how can I

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-19 04:03

    If you run mvn install on that global project, it will be installed in your local repository. Your other projects can then reference it as a dependency:

    
      whatever
      project-commons
      1.0
    
    

    The downside of this simplistic approach is that your other projects won't compile until you've checked-out project-commons and run mvn install.

    A more advanced approach is to deploy a network-accessible repository (such as Artifactory or Nexus) which you can deploy global artifacts to. Artifactory has a community edition which is free. You can then list this repository in your settings file and Maven will resolve artifacts that are uploaded to it.

提交回复
热议问题