Maven Deployment for Specified Projects
在一个多module的maven项目中,如果只想对部分项目执行maven命令,可以用 -pl
参数进行设置。
从mvn
的help信息中可以看到-pl
参数的用法
mvn --help
-pl,--projects <arg> 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
例如一个多module项目,在lib目录和app目录下分别有3个和5个module。

我们可能只想把lib下的内容放到私有仓库nexus中供其他项目成员共用,app目录下的内容没有放到nexus的必要。我们就可以通过指定项目的方式来发布内容。
- 通过
relative path
的方式
mvn -pl lib/common,lib/parent,lib/publisher deploy
- 通过
[groupId]:artifactId
的方式
mvn -pl com.example.event:event-common,com.example.event:event-parent,com.example.event:event-publisher deploy
应用到.gitlab-ci.yml
脚本中
我们应用的是Gitlab-CI工具,所以在项目的.gitlab-ci.yml
脚本中,在deploy阶段的script中增加一条发布脚本。如下所示,这样,每次合并到master分支的源码会自动发布到私有仓库中。
deploy:jdk8:
# Use stage test here, so the pages job may later pickup the created site.
stage: test
tags:
- java
script:
- 'mvn $MAVEN_CLI_OPTS package -DskipTests'
- 'mvn $MAVEN_CLI_OPTS -pl lib/common,lib/parent,lib/publisher deploy -DskipTests'
only:
- master
# Archive up the built documentation site.
artifacts:
expire_in : 2 hrs
paths:
- ./**/target/*.jar
网友评论