[英]Maven: Compile external dependencies within pom.xml
We have a Common
git repository containing a parent pom.xml
and some modules. 我们有一个
Common
git仓库,其中包含一个父pom.xml
和一些模块。 The parent pom.xml
looks like this (simplified): 父
pom.xml
看起来像这样(简化):
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>common</artifactId>
<packaging>pom</packaging>
<modules>
<!-- Utility classes -->
<module>utils</module>
<!-- Data transfer objects -->
<module>dto</module>
</modules>
</dependencyManagement>
<dependencies>
<dependency>
<!-- Version of the module -->
<groupId>group</groupId>
<artifactId>utils</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
</dependency>
...
</dependencies>
</dependencyManagement>
The dependencyManagement
is used to provide consistent versioning across all modules. dependencyManagement
用于在所有模块之间提供一致的版本控制。
Now we want to use parts of the Common
modules in other projects (own git repository each) and still keep the dependencyManagement
. 现在,我们要在其他项目中使用
Common
模块的各个部分(每个项目都有自己的git存储库),并且仍然保留dependencyManagement
。 Thus, we created, for instance, a ProjectX
repository and added Common
as an git-submodule
. 因此,我们创建了一个
ProjectX
存储库,并将Common
添加为git-submodule
。 ProjectX
has the following pom.xml
(simplified): ProjectX
具有以下pom.xml
(简体):
<parent>
<groupId>group</groupId>
<artifactId>common</artifactId>
<relativePath>../Common/pom.xml</relativePath>
</parent>
</dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>utils</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
</dependency>
</dependencies>
This way, we can use classes of Common.utils
and have dependency consistency. 这样,我们可以使用
Common.utils
类,并具有依赖项一致性。 However, after each update of Common
we have to call: 但是,在每次更新
Common
之后,我们必须调用:
mvn clean install
in the Common git-submodule
for ProjectX pom.xml
to find the utils dependency. 在
ProjectX pom.xml
的Common git-submodule
ProjectX pom.xml
中找到utils依赖项。
Question: 题:
maven
command be integrated into the pom.xml? maven
命令集成到pom.xml中吗? The construction with the git submodule is unfortunate. git子模块的构建很不幸。 I would not do it, this is not Maven philosophy.
我不会这样做,这不是Maven的哲学。
I would separate two things: 我将分开两件事:
If you need one of the modules outside the multi-module project, just declare it as dependency in the usual way. 如果您需要多模块项目之外的模块之一,只需以通常的方式将其声明为依赖项即可。
If you want to share configuration or dependencyManagement between the multi-module project and other projects, construct a parent pom that you use for the different projects (may they be multi-module or not). 如果要在多模块项目和其他项目之间共享配置或dependencyManagement,请构造用于不同项目的父pom(无论它们是否为多模块)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.