Maven系列第8篇:大型Maven项目,快速按需任意构建,必备神技能!相知恨晚!

账户模块对外暴露的接口部分,以供外部调用

b2b-account-service

账户模块具体业务实现,依赖于b2b-account-api模块

b2b-order

订单模块,也是包含2个小模块:b2b-order-api和b2b-order-service

b2b-order-api

订单模块对外暴露的接口部分,以供外部调用

b2b-order-service

订单模块具体业务实现,依赖2个模块b2b-order-api、b2b-account-api

搭建项目结构

我们按照上面的需求,使用maven搭建项目结构,具体过程如下。

创建b2b项目

打开idea,点击File->New->Project,如下图:

选择Maven,如下图:

点击上图的Next,输入坐标信息,如下图:

点击上图的Next,输入Project Nameb2b,如下图:

点击上图的Finish,完成项目的创建,如下图:

删除下图中无用的代码:

变成了下面这样:

配置一下idea的maven环境,点击File->Settings,如下图:

点击上面的OK完成配置。

在b2b下创建b2b-account模块

注意这里是创建模块,不是项目了,注意下面的操作过程。

选中b2b项目目录,如下图:

点击File->New->Module,如下图:

选择Maven,如下图:

点击Next,如下图:

点击上面第二个...,将Parent置为None,如下图:

输入坐标信息,如下图:

点击上图中的Next,输入Project nameb2b-account,如下图:

点击Finish,完成b2b-account模块的创建,如下图:

删除b2b-accountsrc目录,如下图:

项目结构变成了下面这样:

在b2b-account模块下面创建b2b-account-api模块

选中b2b-account,如下图:

点击File->New->Module,如下图:

选择Maven,如下图:

点击上图中的Next,如下图:

将上面的Add as module to设置为b2b-account模块,表示新增的这个模块被b2b-account聚合进行管理。

点击Parent后面的...,选择None,将Parent对应的值置为None

如下图:

输入坐标信息,如下图:

点击Next,默认如下图:

我们需要对上面3个输入框的值进行修改,修改成下面这样:

点击Finish,完成创建,如下图:

在b2b-account模块下创建b2b-account-service模块

这个过程参考在b2b-account模块下面创建b2b-account-api模块

在b2b下创建b2b-order模块

这个过程参考在b2b下创建b2b-account模块

在b2b-order模块下面创建b2b-order-api模块

这个过程参考在b2b-account模块下面创建b2b-account-api模块

在b2b-order模块下面创建b2b-order-service模块

这个过程参考在b2b-account模块下面创建b2b-account-api模块

项目结构创建成功

上面都创建成功之后,项目结构如下图

参与过大型maven项目开发的是不是很熟悉很亲切,多数互联网项目的maven结构就是这样一大片maven模块。

引入项目依赖

b2b-account-service依赖于b2b-account-api模块,所以在b2b-account-service/pom.xml中加入下面配置:

              p r o j e c t . g r o u p I d < / g r o u p I d >          < a r t i f a c t I d > b 2 b − a c c o u n t − a p i < / a r t i f a c t I d >          < v e r s i o n > {project.groupId}</groupId>         <artifactId>b2b-account-api</artifactId>         <version> project.groupId</groupId>        <artifactId>b2baccountapi</artifactId>        <version>{project.version}     

由于项目的groupId,version都是一样的,所以直接通过${}这种方式引用了。

b2b-order-service依赖2个模块b2b-order-api、b2b-account-api,所以在b2b-order-service/pom.xml中加入下面配置:

              p r o j e c t . g r o u p I d < / g r o u p I d >          < a r t i f a c t I d > b 2 b − a c c o u n t − a p i < / a r t i f a c t I d >          < v e r s i o n > {project.groupId}</groupId>         <artifactId>b2b-account-api</artifactId>         <version> project.groupId</groupId>        <artifactId>b2baccountapi</artifactId>        <version>{project.version}                    p r o j e c t . g r o u p I d < / g r o u p I d >          < a r t i f a c t I d > b 2 b − o r d e r − a p i < / a r t i f a c t I d >          < v e r s i o n > {project.groupId}</groupId>         <artifactId>b2b-order-api</artifactId>         <version> project.groupId</groupId>        <artifactId>b2borderapi</artifactId>        <version>{project.version}     

此时每个模块pom.xml如下
b2b/pom.xml
<?xml version="1.0" encoding="UTF-8"?>     4.0.0     com.javacode2018     b2b     pom     1.0-SNAPSHOT              b2b-account         b2b-order     
b2b-account/pom.xml
<?xml version="1.0" encoding="UTF-8"?>     4.0.0     com.javacode2018     b2b-account     pom     1.0-SNAPSHOT              b2b-account-api         b2b-account-service     
b2b-account-api/pom.xml
<?xml version="1.0" encoding="UTF-8"?>     4.0.0     com.javacode2018     b2b-account-api     1.0-SNAPSHOT
b2b-account-service/pom.xml
<?xml version="1.0" encoding="UTF-8"?>     4.0.0     com.javacode2018     b2b-account-service     1.0-SNAPSHOT                           ${project.groupId}             b2b-account-api             ${project.version}              
b2b-order/pom.xml
<?xml version="1.0" encoding="UTF-8"?>     4.0.0     com.javacode2018     b2b-order     pom     1.0-SNAPSHOT              b2b-order-api         b2b-order-service     
b2b-order-api/pom.xml
<?xml version="1.0" encoding="UTF-8"?>     4.0.0     com.javacode2018     b2b-order-api     1.0-SNAPSHOT
b2b-order-service/pom.xml
<?xml version="1.0" encoding="UTF-8"?>     4.0.0     com.javacode2018     b2b-order-service     1.0-SNAPSHOT                           ${project.groupId}             b2b-account-api             ${project.version}                               ${project.groupId}             b2b-order-api             ${project.version}              

注意:上面项目的结构属于父子结构,使用maven中聚合的方式进行管理的,对应聚合不是太了解的,可以看上篇文章有详细介绍。

b2b中包含了2个子模块b2b_accountb2b_order,这3个package都是pom。

b2b_account中包含了2个子模块,2个子模块package是默认的jar类型。

b2b_order中包含了2个子模块,2个子模块package是默认的jar类型。

反应堆

上面项目都开发好了,我们需要安装到本地仓库,一般情况下,我们会这么做,在b2b/pom.xml所在目录执行下面命令:

mvn clean install

我们来感受一下这个命令的效果:

D:\code\IdeaProjects\b2b>mvn clean install [INFO] Scanning for projects… [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] b2b-account-api                                                    [jar] [INFO] b2b-account-service                                                [jar] [INFO] b2b-account                                                        [pom] [INFO] b2b-order-api                                                      [jar] [INFO] b2b-order-service                                                  [jar] [INFO] b2b-order                                                          [pom] [INFO] b2b                                                                [pom] [INFO] [INFO] ------------------< com.javacode2018:b2b-account-api >------------------ [INFO] Building b2b-account-api 1.0-SNAPSHOT                              [1/7] [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-account-api — [INFO] Deleting D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ b2b-account-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ b2b-account-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ b2b-account-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\src\test\resources [INFO] [INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ b2b-account-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ b2b-account-api — [INFO] No tests to run. [INFO] [INFO] — maven-jar-plugin:2.4:jar (default-jar) @ b2b-account-api — [INFO] Building jar: D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target\b2b-account-api-1.0-SNAPSHOT.jar [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-account-api — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target\b2b-account-api-1.0-SNAPSHOT.jar to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-api\1.0-SNAPSHOT\b2b-account-api-1.0-SNAPSHOT.jar [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-api\1.0-SNAPSHOT\b2b-account-api-1.0-SNAPSHOT.pom [INFO] [INFO] ----------------< com.javacode2018:b2b-account-service >---------------- [INFO] Building b2b-account-service 1.0-SNAPSHOT                          [2/7] [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-account-service — [INFO] Deleting D:\code\IdeaProjects\b2b\b2b-account\b2b-account-service\target [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ b2b-account-service — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ b2b-account-service — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ b2b-account-service — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\code\IdeaProjects\b2b\b2b-account\b2b-account-service\src\test\resources [INFO] [INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ b2b-account-service — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ b2b-account-service — [INFO] No tests to run. [INFO] [INFO] — maven-jar-plugin:2.4:jar (default-jar) @ b2b-account-service — [INFO] Building jar: D:\code\IdeaProjects\b2b\b2b-account\b2b-account-service\target\b2b-account-service-1.0-SNAPSHOT.jar [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-account-service — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-service\target\b2b-account-service-1.0-SNAPSHOT.jar to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-service\1.0-SNAPSHOT\b2b-account-service-1.0-SNAPSHOT.jar [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-service\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-service\1.0-SNAPSHOT\b2b-account-service-1.0-SNAPSHOT.pom [INFO] [INFO] --------------------< com.javacode2018:b2b-account >-------------------- [INFO] Building b2b-account 1.0-SNAPSHOT                                  [3/7] [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-account — [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-account — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-account\1.0-SNAPSHOT\b2b-account-1.0-SNAPSHOT.pom [INFO] [INFO] -------------------< com.javacode2018:b2b-order-api >------------------- [INFO] Building b2b-order-api 1.0-SNAPSHOT                                [4/7] [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-order-api — [INFO] Deleting D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\target [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ b2b-order-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ b2b-order-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ b2b-order-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\src\test\resources [INFO] [INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ b2b-order-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ b2b-order-api — [INFO] No tests to run. [INFO] [INFO] — maven-jar-plugin:2.4:jar (default-jar) @ b2b-order-api — [INFO] Building jar: D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\target\b2b-order-api-1.0-SNAPSHOT.jar [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-order-api — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\target\b2b-order-api-1.0-SNAPSHOT.jar to C:\Users\Think.m2\repository\com\javacode2018\b2b-order-api\1.0-SNAPSHOT\b2b-order-api-1.0-SNAPSHOT.jar [INFO] Installing D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-order-api\1.0-SNAPSHOT\b2b-order-api-1.0-SNAPSHOT.pom [INFO] [INFO] -----------------< com.javacode2018:b2b-order-service >----------------- [INFO] Building b2b-order-service 1.0-SNAPSHOT                            [5/7] [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-order-service — [INFO] Deleting D:\code\IdeaProjects\b2b\b2b-order\b2b-order-service\target [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ b2b-order-service — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ b2b-order-service — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ b2b-order-service — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\code\IdeaProjects\b2b\b2b-order\b2b-order-service\src\test\resources [INFO] [INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ b2b-order-service — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ b2b-order-service — [INFO] No tests to run. [INFO] [INFO] — maven-jar-plugin:2.4:jar (default-jar) @ b2b-order-service — [INFO] Building jar: D:\code\IdeaProjects\b2b\b2b-order\b2b-order-service\target\b2b-order-service-1.0-SNAPSHOT.jar [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-order-service — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-order\b2b-order-service\target\b2b-order-service-1.0-SNAPSHOT.jar to C:\Users\Think.m2\repository\com\javacode2018\b2b-order-service\1.0-SNAPSHOT\b2b-order-service-1.0-SNAPSHOT.jar [INFO] Installing D:\code\IdeaProjects\b2b\b2b-order\b2b-order-service\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-order-service\1.0-SNAPSHOT\b2b-order-service-1.0-SNAPSHOT.pom [INFO] [INFO] ---------------------< com.javacode2018:b2b-order >--------------------- [INFO] Building b2b-order 1.0-SNAPSHOT                                    [6/7] [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-order — [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-order — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-order\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-order\1.0-SNAPSHOT\b2b-order-1.0-SNAPSHOT.pom [INFO] [INFO] ------------------------< com.javacode2018:b2b >------------------------ [INFO] Building b2b 1.0-SNAPSHOT                                          [7/7] [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b — [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b — [INFO] Installing D:\code\IdeaProjects\b2b\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b\1.0-SNAPSHOT\b2b-1.0-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for b2b 1.0-SNAPSHOT: [INFO] [INFO] b2b-account-api … SUCCESS [  1.806 s] [INFO] b2b-account-service … SUCCESS [  0.298 s] [INFO] b2b-account … SUCCESS [  0.082 s] [INFO] b2b-order-api … SUCCESS [  0.229 s] [INFO] b2b-order-service … SUCCESS [  0.254 s] [INFO] b2b-order … SUCCESS [  0.058 s] [INFO] b2b … SUCCESS [  0.069 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time:  3.072 s [INFO] Finished at: 2019-11-20T16:03:27+08:00 [INFO] ------------------------------------------------------------------------

注意上面有这样的输出:

[INFO] Reactor Build Order: [INFO] [INFO] b2b-account-api                                                    [jar] [INFO] b2b-account-service                                                [jar] [INFO] b2b-account                                                        [pom] [INFO] b2b-order-api                                                      [jar] [INFO] b2b-order-service                                                  [jar] [INFO] b2b-order                                                          [pom] [INFO] b2b                                                                [pom]

maven会根据模块之间的依赖关系,然后会得到所有模块的构建顺序,上面共有7个pom.xml文件,也就是7个maven构件,按照上面列出的顺序依次进行构建。

可以看到b2b-account-api是被其他一些模块依赖的,所以这个放在了第一个。

mvn命令对多模块构件时,会根据模块的依赖关系而得到模块的构建顺序,这个功能就是maven的反应堆(reactor)做的事情,反应堆会根据模块之间的依赖关系、聚合关系、继承关系等等,从而计算得出一个合理的模块构建顺序,所以反应堆的功能是相当强大的。

按需随意构建

有这样的一种场景:b2b-account-apib2b-account-serviceb2b-order-service依赖了,所以当b2b-account-api有修改的时候,我们希望他们3个都能够被重新构建一次,而不是去对所有的模块都进行重新构建,我们只希望被影响的模块都能够参与重新构建,大家有什么好的办法?

上面列出的只是2个模块的功能,真正的电商项目还有很多模块,如果每次修改一个模块,我们都去重新打包所有的模块,这个构建过程耗时是非常久的,只能干等着,我们需要的是按需构建,需要构建哪些模块让我们自己能够随意指定,这样也可以加快构建的速度,所以我们需要这样的功能

maven反应堆帮我们考虑到了这种情况,mvn命令提供了一些功能可以帮我们实现这些操作,我们看一下mvn的帮助文档,mvn -h可以查看帮助,如下:

D:\code\IdeaProjects\b2b>mvn -h usage: mvn [options] [<goal(s)>] [<phase(s)>] Options:  -am,–also-make                        If project list is specified, also                                         build projects required by the                                         list  -amd,–also-make-dependents            If project list is specified, also                                         build projects that depend on                                         projects on the list  -B,–batch-mode                        Run in non-interactive (batch)                                         mode (disables output color)  -b,–builder                      The id of the build strategy to                                         use  -C,–strict-checksums                  Fail the build if checksums don’t                                         match  -c,–lax-checksums                     Warn if checksums don’t match  -cpu,–check-plugin-updates            Ineffective, only kept for                                         backward compatibility  -D,–define                       Define a system property  -e,–errors                            Produce execution error messages  -emp,–encrypt-master-password    Encrypt master security password  -ep,–encrypt-password            Encrypt server password  -f,–file                         Force the use of an alternate POM                                         file (or directory with pom.xml)  -fae,–fail-at-end                     Only fail the build afterwards;                                         allow all non-impacted builds to                                         continue  -ff,–fail-fast                        Stop at first failure in                                         reactorized builds  -fn,–fail-never                       NEVER fail the build, regardless                                         of project result  -gs,–global-settings             Alternate path for the global                                         settings file  -gt,–global-toolchains           Alternate path for the global                                         toolchains file  -h,–help                              Display help information  -l,–log-file                     Log file where all build output                                         will go (disables output color)  -llr,–legacy-local-repository         Use Maven 2 Legacy Local                                         Repository behaviour, ie no use of                                         _remote.repositories. Can also be                                         activated by using                                         -Dmaven.legacyLocalRepo=true  -N,–non-recursive                     Do not recurse into sub-projects  -npr,–no-plugin-registry              Ineffective, only kept for                                         backward compatibility  -npu,–no-plugin-updates               Ineffective, only kept for                                         backward compatibility  -nsu,–no-snapshot-updates             Suppress SNAPSHOT updates  -ntp,–no-transfer-progress            Do not display transfer progress                                         when downloading or uploading  -o,–offline                           Work offline  -P,–activate-profiles            Comma-delimited list of profiles                                         to activate  -pl,–projects                    Comma-delimited list of specified                                         reactor projects to build instead                                         of all projects. A project can be                                         specified by [groupId]:artifactId                                         or by its relative path  -q,–quiet                             Quiet output - only show errors  -rf,–resume-from                 Resume reactor from specified                                         project  -s,–settings                     Alternate path for the user                                         settings file  -t,–toolchains                   Alternate path for the user                                         toolchains file  -T,–threads                      Thread count, for instance 2.0C                                         where C is core multiplied  -U,–update-snapshots                  Forces a check for missing                                         releases and updated snapshots on                                         remote repositories  -up,–update-plugins                   Ineffective, only kept for                                         backward compatibility  -v,–version                           Display version information  -V,–show-version                      Display version information                                         WITHOUT stopping build  -X,–debug                             Produce execution debug output

上面列出了mvn命令后面的一些选项,有几个选项本次我们需要用到,如下:

-pl,–projects

构件指定的模块,arg表示多个模块,之间用逗号分开,模块有两种写法

-pl 模块1相对路径 [,模块2相对路径] [,模块n相对路径] -pl [模块1的groupId]:模块1的artifactId [,[模块2的groupId]:模块2的artifactId] [,[模块n的groupId]:模块n的artifactId]

举例:

下面命令都是在b2b/pom.xml来运行

mvn clean install -pl b2b-account mvn clean install -pl b2b-account/b2b-account-api mvn clean install -pl b2b-account/b2b-account-api,b2b-account/b2b-account-service mvn clean install -pl :b2b-account-api,b2b-order/b2b-order-api mvn clean install -pl :b2b-account-api,:b2b-order-service

-rf,–resume-from

从指定的模块恢复反应堆

-am,–also-make

同时构建所列模块的依赖模块

-amd,–also-make-dependents

同时构件依赖于所列模块的模块

下面我们通过6个案例细说上面这些用法。

注意:下面所有案例都在b2b/pom.xml所在目录执行。

案例1

只构建p-account模块,运行命令

mvn clean install -pl b2b-account

效果如下:

D:\code\IdeaProjects\b2b>mvn clean install -pl b2b-account [INFO] Scanning for projects… [INFO] [INFO] --------------------< com.javacode2018:b2b-account >-------------------- [INFO] Building b2b-account 1.0-SNAPSHOT [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-account — [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-account — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-account\1.0-SNAPSHOT\b2b-account-1.0-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time:  0.907 s [INFO] Finished at: 2019-11-20T16:12:51+08:00 [INFO] ------------------------------------------------------------------------

可以看到只构建了b2b-account

案例2

只构建b2b-account-api模块,运行命令:

mvn clean install -pl b2b-account/b2b-account-api

效果如下:

D:\code\IdeaProjects\b2b>mvn clean install -pl b2b-account/b2b-account-api [INFO] Scanning for projects… [INFO] [INFO] ------------------< com.javacode2018:b2b-account-api >------------------ [INFO] Building b2b-account-api 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-account-api — [INFO] Deleting D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ b2b-account-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ b2b-account-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ b2b-account-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\src\test\resources [INFO] [INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ b2b-account-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ b2b-account-api — [INFO] No tests to run. [INFO] [INFO] — maven-jar-plugin:2.4:jar (default-jar) @ b2b-account-api — [INFO] Building jar: D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target\b2b-account-api-1.0-SNAPSHOT.jar [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-account-api — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target\b2b-account-api-1.0-SNAPSHOT.jar to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-api\1.0-SNAPSHOT\b2b-account-api-1.0-SNAPSHOT.jar [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-api\1.0-SNAPSHOT\b2b-account-api-1.0-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time:  2.853 s [INFO] Finished at: 2019-11-20T16:14:37+08:00 [INFO] ------------------------------------------------------------------------

上面使用的是相对路径的写法,还有2种写法,大家可以去试试,如下:

mvn clean install -pl :b2b-account-api mvn clean install -pl com.javacode2018:b2b-account-api

案例3

构建b2b-account-api和b2b-order-api,运行下面命令:

mvn clean install -pl b2b-account/b2b-account-api,b2b-order/b2b-order-api

效果如下:

D:\code\IdeaProjects\b2b>mvn clean install -pl b2b-account/b2b-account-api,b2b-order/b2b-order-api [INFO] Scanning for projects… [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] b2b-account-api                                                    [jar] [INFO] b2b-order-api                                                      [jar] [INFO] [INFO] ------------------< com.javacode2018:b2b-account-api >------------------ [INFO] Building b2b-account-api 1.0-SNAPSHOT                              [1/2] [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-account-api — [INFO] Deleting D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ b2b-account-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ b2b-account-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ b2b-account-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\src\test\resources [INFO] [INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ b2b-account-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ b2b-account-api — [INFO] No tests to run. [INFO] [INFO] — maven-jar-plugin:2.4:jar (default-jar) @ b2b-account-api — [INFO] Building jar: D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target\b2b-account-api-1.0-SNAPSHOT.jar [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-account-api — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\target\b2b-account-api-1.0-SNAPSHOT.jar to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-api\1.0-SNAPSHOT\b2b-account-api-1.0-SNAPSHOT.jar [INFO] Installing D:\code\IdeaProjects\b2b\b2b-account\b2b-account-api\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-account-api\1.0-SNAPSHOT\b2b-account-api-1.0-SNAPSHOT.pom [INFO] [INFO] -------------------< com.javacode2018:b2b-order-api >------------------- [INFO] Building b2b-order-api 1.0-SNAPSHOT                                [2/2] [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] — maven-clean-plugin:2.5:clean (default-clean) @ b2b-order-api — [INFO] Deleting D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\target [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ b2b-order-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ b2b-order-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ b2b-order-api — [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\src\test\resources [INFO] [INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ b2b-order-api — [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ b2b-order-api — [INFO] No tests to run. [INFO] [INFO] — maven-jar-plugin:2.4:jar (default-jar) @ b2b-order-api — [INFO] Building jar: D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\target\b2b-order-api-1.0-SNAPSHOT.jar [INFO] [INFO] — maven-install-plugin:2.4:install (default-install) @ b2b-order-api — [INFO] Installing D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\target\b2b-order-api-1.0-SNAPSHOT.jar to C:\Users\Think.m2\repository\com\javacode2018\b2b-order-api\1.0-SNAPSHOT\b2b-order-api-1.0-SNAPSHOT.jar [INFO] Installing D:\code\IdeaProjects\b2b\b2b-order\b2b-order-api\pom.xml to C:\Users\Think.m2\repository\com\javacode2018\b2b-order-api\1.0-SNAPSHOT\b2b-order-api-1.0-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for b2b-account-api 1.0-SNAPSHOT: [INFO] [INFO] b2b-account-api … SUCCESS [  2.874 s] [INFO] b2b-order-api … SUCCESS [  0.393 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time:  3.554 s [INFO] Finished at: 2019-11-20T16:15:57+08:00 [INFO] ------------------------------------------------------------------------

上面输出中可以看到只构建了2个目标模块。

案例4

我们只修改了b2b-account-api代码,所以我希望对这个重新打包,并且对这个有依赖的也重新打包,所以需要打包下面3个模块:

b2b-account-api b2b-account-service b2b-order-service

上面列表中的后面两个是依赖于b2b-account-api的,可以在b2b/pom.xml中执行下面命令:

mvn clean install -pl b2b-account/b2b-account-api -amd

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
b2b-order-service

上面列表中的后面两个是依赖于b2b-account-api的,可以在b2b/pom.xml中执行下面命令:

mvn clean install -pl b2b-account/b2b-account-api -amd

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

[外链图片转存中…(img-wrOGO94i-1715828551165)]

[外链图片转存中…(img-RSslrAXN-1715828551165)]

[外链图片转存中…(img-GdqqjIuA-1715828551166)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值