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

£可爱£侵袭症+ 提交于 2019-12-01 18:40:43

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:

<dependency>
  <groupId>whatever</groupId>
  <artifactId>project-commons</artifactId>
  <version>1.0</version>
</dependency>

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.

ivoruJavaBoy

Using relative path to include some submodules is not a good practice...you will have a lot of problems.

Can not you just put the common project as a dependency of the parent module...

In this way you will have that "common project" in all the submodule that declare the parent project as a parent...

Why do you want to compile your "common" project every time you compile the parent pom?

Edited:

YOUR SVN:

svn/MyGlobalProject/project-commons/pom.xml           //should be shared among different projects
svn/MyProject/web-parent/trunk/pom.xml                //the parent pom used to build the    application
svn/MyProject/web-parent/trunk/project-domain/pom.xml //submodule 1
svn/MyProject/web-parent/trunk/project-web/pom.xml    //submodule 2

PARENT POM.XML:

<project>
    <groupId>de.project</groupId>
    <artifactId>project-parent</artifactId>
    <packaging>pom</packaging>

    <dependencies>
       <dependency>
      <groupId>de.project</groupId>
      <artifactId>project-commons</artifactId>
      <version>${common.project.version}</version>
       <dependency>
    <dependencies>

<modules>
    <module>project-domain</module>
    <module>project-web</module>
</modules>

Just like this... in that way project-domain and project-web will inherit that dependency, and you will able to use it everywhere you want in submodules...

Than the use of dependency management could be a good improvements

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