Java Maven Multi-module Source Construction

Maven Multi-module Project Build Identification Strategy

Maven multi-module projects are divided according to the pom.xml file (hereinafter referred to as pom), and Kato’s recognition of it is also based on the pom. The main purpose is to identify the specific module (module) build command and start command. Build. The function of the command is to specify the module to be built, which is similar to the mvn command “mvn install -pl’module name' -am”. The function of the start command is to specify the Jar package to be executed after the build is completed, which is similar to " web: java $JAVA_OPTS -jar *.jar" command.

Identification strategy:

  1. Find the pom under the corresponding module according to the module tag in the modules in the root pom.
  2. If the value of the packing tag in the pom is jar (war), then the module name and jar (war) package name corresponding to the current pom will be parsed. If the value of the packing tag is empty, it will be considered as a jar.
  3. The module name consists of the value of the module tag in the parent pom, separated by “/”, similar to: rbd-worker/rbd-thirdparty.
  4. The jar(war) package name is ${artifaceId}-*.jar(war) by default. If the finalName tag is set, the value of the finalName tag will be used; if the finalName tag uses the variable ${project.name} or $ (project.aritfactId), the value corresponding to the variable will be used; if other variables are used, directly use * instead, that is: *.jar(war).
  5. If the value of the packing tag in pom is pom and the module in the modules tag is more than 1, repeat 1 to 5.

Because the wildcard character * is used in many places, when more than one jar (war) is constructed, the recognized jar (war) package may not be able to determine the only package; or the recognized jar (war) package is wrong, At this time, the user needs to modify it manually.

Multi-module Project Source Code Specification

Because Kato’s recognition of Maven multi-module projects is based on pom, so the pom.xml file you are writing should conform to the pom specification. For the pom specification, please refer to: POM Reference

Case

Take SPRING CLOUD microservices deployed in KATO case in the Pig project in the article Java source code deployment part as an example, one-time multi-module deployment Pig project (other dependencies such as Mysql are installed by default).

Module Construction

Create a new application and name it spring-cloud

Get the project clone/download address: https://gitee.com/log4j/pig.git

  1. Create from source code, select custom source code, fill in project address
  1. If it is a multi-module project will be recognized, choose to enter the multi-module build configuration item
  1. According to the article Case of Spring Cloud Microservice Deployment in KATO, it can be seen that the following components need to be deployed and run, and then checked and built
  1. Completed rendering (Java part only)
  1. View the source information of an application

In this way, the multi-module construction of the Pig project is completed. For other subsequent steps, please refer to SPRING CLOUD microservice deployment in KATO case