Maven多模块项目

1.项目结构-父项目

其中parent是父项目,这个父项目的父项目是springboot,我搭建这个多模块的项目的目的主要是为了研究学习springbatch

父项目的pom文件内容:

<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">

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.8.RELEASE</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.wx.onepass</groupId>
    <artifactId>onepass-parent</artifactId>
    <packaging>pom</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>onepass-parent</name>

    <modules>
        <module>onepass-dependencies</module>
        <module>onepass-test</module>
        <module>onepass-batch</module>
        <module>onepass-web</module>
    </modules>
    
    <properties>
        <!-- 依赖包版本号 -->
        <junit.version>3.8.1</junit.version>
        <spring-boot-legacy.version>1.1.0.RELEASE</spring-boot-legacy.version>
    </properties>
    
    <dependencyManagement>
        <dependencies>
            <!-- junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
        <!-- 引入spring-boot-starter-web,因为我需要它提供的web功能,具体有哪些功能目前还没有仔细查过-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 将starter-web中默认的tomcat替换成jetty -->
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>  
                <exclusion>
                    <groupId>org.springframework.boot</groupId>  
                    <artifactId>spring-boot-starter-tomcat</artifactId>  
                </exclusion>  
            </exclusions>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-jetty</artifactId>  
        </dependency>
    </dependencies>
    
    <build>
        <finalName>onepass</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5</version>
                <configuration>
                    <!-- 指定source和target的版本 -->
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2.项目结构-子项目

之前一直没有搞懂一件事情,就是这样的多模块有父有子的项目,其中的子模块是否需要配置相互的依赖,比如web中需要依赖batch,需要需要在web模块的dependencies中配置对batch的依赖。现在我很明确了是需要的。下面以web项目的pom文件为例

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wx.onepass</groupId>
        <artifactId>onepass-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../onepass-parent</relativePath>
    </parent>
    <artifactId>onepass-web</artifactId>
    <packaging>war</packaging>
    <name>onepass-web Maven Webapp</name>
    
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.wx.onepass</groupId>
            <artifactId>onepass-batch</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>onepass-web</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5</version>
                <configuration>
                    <!-- 指定source和target的版本 -->
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 

3.Maven Depedencies里面依赖的子模块什么时候是JAR包,什么时候是项目文件夹

从上图可以看出,onepass-batch是以jar包的形式存在其中的,猜想这是因为我对parent已经做了clean install,如果没有做这一步,应该onepass-batch应该是文件夹,猜想,还没有验证,验证了再来更新

原文地址:https://www.cnblogs.com/heben/p/6956035.html