First, create the parent project
"New", "Maven Project"
Select "Create a simple project ..." in the pop-up screen
Second, create sub-projects
Select the parent project you just built, and in the pop-up menu, click "New" and "other".Maven Module】
Third, optimize the configuration
The subproject created by the previous step pom.xml
has a node in it, parent
so he can inherit information about the parent project.
In a subproject pom.xml
, the child project is the groupId
same as the version
Normal and parent project, so you can delete the two parameters of the project, which automatically inherits the value of the parent item.
Similarly, if any of the other properties, all child items are the same, you can move up to the parent project setting, and the subproject does not need to be set repeatedly. For example, <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
you can set only one time in a parent project.
In addition to this situation, there is a situation, that is, dependencies and plug-ins. dependencies and plug-ins are such that a dependency or plug-in may be used by most sub-projects, but there may be some sub-projects that do not need to be used, so it is not appropriate to simply inherit in the way described above.
Manen offers dependencyManagement
and pluginManagement
two labels. Using these two tags, you can uniformly manage dependencies and plug-in configuration parameters, such as version numbers, in the parent project. In sub-projects, only the dependencies and plug-ins that need to be used are listed groupId
artifactId
, and other information is automatically retrieved from the parent project management information.
example, parent project:
<dependencymanagement> <Dependencies> <Dependency> <groupId>Junit</groupId> <Artifactid>Junit</Artifactid> <version>${junit.version}</version> <Scope>Test</Scope> </Dependency> <Dependency> <groupId>Org.slf4j</groupId> <Artifactid>Slf4j-log4j12</Artifactid> <version>1.7.5</version> <Scope>Test</Scope> </Dependency> <Dependency> <groupId>Org.slf4j</groupId> <Artifactid>Slf4j-api</Artifactid> <version>1.7.5</version> </Dependency> </Dependencies></dependencymanagement>
Sub-project:
<Dependencies> <Dependency> <groupId>Junit</groupId> <Artifactid>Junit</Artifactid> </Dependency></Dependencies>
Reference:
http://ju.outofmemory.cn/entry/75620
Http://www.cnblogs.com/qiyebao/p/5300539.html
Eclipse creates MAVEN multi-module engineering