如何在项目上下文之外包含maven模块? [英] How to include a maven module outside of the project context?

查看:236
本文介绍了如何在项目上下文之外包含maven模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在某种全局项目目录中有一个模块,这样我就可以在使用该公共代码的所有其他项目中包含该模块。

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.

但是,我怎么能告诉maven父 pom 来包含和编译这个全局共享模块?
以下不起作用:

But how can I then tell a maven parent pom to include and compile this global shared module? The following does not work:

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

父pom.xml:

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

    <modules>
        <module>project-domain</module>
        <module>project-web</module>
        <module>../project-commons</module> <!-- Error -->
    </modules>
</project>

mvn package 结果:

Child module trunk\project-commons of trunk\pom.xml does not exist


推荐答案

如果您在该全球项目上运行 mvn install ,它将安装在您的本地存储库中。您的其他项目可以将其作为依赖项引用:

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>

这种简单方法的缺点是你的其他项目在你检查之后才会编译 - out project-commons 并运行 mvn install

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.

更高级的方法是部署一个可通过网络访问的存储库(例如 Artifactory 或Nexus)可以部署全局工件。 Artifactory有一个免费的社区版本。然后,您可以在设置文件中列出此存储库,Maven将解析上传到它的工件。

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.

这篇关于如何在项目上下文之外包含maven模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆