如何使Maven构建依赖项目 [英] how to make maven build dependent project
问题描述
我有一个与其他项目有多个依赖项的项目.
I have project with several dependencies on other project.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group1</groupId>
<artifactId>artifact1<artifactId>
<name>RealtyRegistry</name>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>group1</groupId>
<artifactId>artifact2</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>group1</groupId>
<artifactId>artifact3</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
所有这些都是我同时开发的.我将版本添加到所有项目的文件中,并且需要与相关项目一起构建主项目.对于没有树状结构的项目该怎么做?
All of them developed by me simultaniously. I add edition to files of all of project and i need to build main project together with dependent ones. How to do that for projects without tree structure?
对于层级项目,可以有2棵或更多棵覆盖树,例如:A取决于B,C; D取决于C,E; A和D是独立的.
There can be 2 or more covering trees for projects hierachy, for example: A depends on B,C; D depends on C,E; A and D are independent.
推荐答案
您可以使用模块"一起构建多个项目.通常,您可以通过使用<packaging>pom</packaging>
创建一个母亲"项目,并使用<modules>
标记将您的真实项目添加为模块来完成此操作.然后,当您构建母亲"项目时,所有模块都将以正确的顺序自动构建.
You can build multiple projects together using "Modules". Normally, you would do this by creating a "mother" project with <packaging>pom</packaging>
and adding your real project as modules using the <modules>
tag. Then, when you build the "mother" project, all modules are automatically built in the right order.
以下是示例行家中的示例本书:
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
请注意,这要求您将模块包含在相应命名的子文件夹中.例如,您将在某个文件夹中放置母亲" pom:
Note that this requires you to have your modules in subfolders that are named accordingly. For example, you would have the "mother" pom in some folder:
/.../my-project/
以及其中的模块:
/.../my-project/simple-weather/
/.../my-project/simple-webapp/
有关更多信息,请阅读第6章.这本书,可以在Sonatype网站上免费获得.
For more information, read Chapter 6. A Multi-module Project of the book, it's freely available on the Sonatype website.
这篇关于如何使Maven构建依赖项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!