Maven使用说明及规范
此文档主要说明Maven的基础使用方式,以及在使用过程过程中需要遵守哪些默认的准则。我们工作中会经常写maven的配置,但是很多maven使用细节你可能并不知道,但你掌握后使用maven会更加上手。
Maven是什么?
Apache Maven是一个软件项目管理工具。基于项目对象模型(POM)的概念,Maven可以通过一小段描述信息来管理项目的构建,报告和文档。 Maven的核心是一个插件执行框架, 所有工作都是通过插件完成的。最熟悉的插件如我们比较常用的:
- clean(https://github.com/apache/maven-clean-plugin/)
- compiler(https://github.com/apache/maven-compiler-plugin/ )
- install(https://github.com/apache/maven-install-plugin/ )
- deploy(https://github.com/apache/maven-deploy-plugin/ )
除了这些默认流程的插件,我们针对Maven的工作机制也制作了自己的插件,如 授权系统抽取api.json文件的插件,如通过erm对象描述文件生成Entity实体的插件等(https://gitee.com/kekingcn/kk-erm-maven-plugin)。
基本使用
基础信息
定义pom模型的基本信息
使用Maven构建的项目,首先需要在pom.xml文件中写明基本信息,如:
-
<groupId>com.yudianbank.projectgroupId> //组织ID
-
<artifactId>salesAppParentartifactId>//工程名称
-
<packaging>pompackaging>//打包方式,如:jar、war、pom、rar等
-
<version>1.0-RELEASESversion> //版本号
由groupId、artifactId、version三个元素定位唯一的jar信息,常说的发个Maven坐标也就是这三个元素
modules 节点,聚合子模块,
在多模块的项目中使用,用来定义子模块,一般多模块项目中,父模块的packaging都定义为pom
-
<modules>
-
<module>apimodule>
-
<module>producermodule>
-
modules>
parent节点,继承其他pom模型的属性
如:在spring boot项目中,会有如下parent节点,用来继承spring boot已经定义好的pom
-
<parent>
-
<groupId>org.springframework.bootgroupId>
-
<artifactId>spring-boot-starter-parentartifactId>
-
<version>1.5.7.RELEASEversion>
-
<relativePath/>
-
parent>
properties 节点,定义属性信息
这个节点一般用于定义一些属性,用来作为插件的默认值。在这里定义的属性可以贯穿Maven build的整个生命周期,Maven属性是值占位符,可以在pom中通过${XXX}符号来使用
-
<properties>
-
<spring-cloud.version>Dalston.SR3spring-cloud.version>
-
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
-
<compiler.version>1.8compiler.version>
-
<powermock.version>1.6.4powermock.version>
-
<checkstyle.version>6.18checkstyle.version>
-
properties>
除了如上手动定义的一些属性,我们还可以通过如下的方式,访问到其他的一些变量,如:
- env.X : 使用“env.”对变量进行前缀。将返回shell的环境变量。例如,$ {env.PATH}包含PATH环境变量。 注意:虽然环境变量本身在Windows上不区分大小写,但属性的查找区分大小写。换句话说,当Windows shell为%PATH%和%Path%返回相同的值时,Maven会区分$ {env.PATH}和$ {env.Path}。从Maven 2.1.0开始,为了可靠性,环境变量的名称被归一化为所有大写。
- project.x : POM中的标记路径将包含相应元素的值。例如: 1.0 version> project>可通过$ {project.version}访问。
- settings.x : Mavne Home路径的settings.xml将包含相应的元素的值。例如: false offline> settings>可通过$ {settings.offline}访问。
- Java系统属性 : 通过java.lang.System.getProperties()访问的所有属性都可用作POM属性,例如${java.home}。
dependencies 节点,定义项目依赖
-
<dependencies>
-
<dependency>
-
<groupId>org.springframework.cloudgroupId>
-
<artifactId>spring-cloud-dependenciesartifactId>
-
<version>${spring-cloud.version}version>
-
dependency>
-
dependencies>
除了基本的groupId、artifactId、version坐标属性外,dependency节点中还包括如下的常用属性设置
- type : 依赖的类型,默认是jar
- classifier : 分类器,额外的jar坐标标记,用来依赖那些从同一个POM中打出的不同的jar包。
- scope : 依赖的jar的作用范围,可选(compile,runtime,test,system,provided)
compile : 这是默认范围。所有类路径中都提供了编译依赖项。此外,这些依赖项将传播到依赖项目
runtime : 这很像compile,但表示您希望JDK或容器在运行时提供它。它仅在编译和测试类路径中可用,并且不可传递。
test : 此范围表示正常使用应用程序不需要依赖项,并且仅适用于测试编译和执行阶段。它不是传递性的。
provided :这很像compile,但表示您希望JDK或容器在运行时提供它。它仅在编译和测试类路径中可用,并且不可传递。
system :此范围与provided的类似,只是您必须提供明确包含它的JAR,声明后不会在存储库中查找
- Systempath:当scope为system生效,用于定义本地依赖的路径
- optional :是否启用依赖传递,默认false需要依赖传递。如A依赖B,B依赖C,默认情况下A中会有C的依赖,如果在依赖B时设置optional为true,则A中不会有C的依赖
- exclusions :排除依赖传递
dependencies -> exclusions 节点,排除依赖传递
有时候为了解决项目依赖冲突,需要排除依赖的jar包通过Maven依赖传递特性引用的其他jar,如:
-
<dependency>
-
<groupId>com.yudianbank.publicgroupId>
-
<artifactId>pdfartifactId>
-
<version>1.1-RELEASESversion>
-
<exclusions>
-
<exclusion>
-
<groupId>commons-poolgroupId>
-
<artifactId>commons-poolartifactId>
-
exclusion>
-
exclusions>
-
dependency>
关于Maven依赖传递特性,当出现多个jar依赖相同的不同版本jar时,遵循两个原则来引用:
- 最短路径原则:如A->B->C-D1 , A->B1->D2 , 那么最终项目A依赖的D的版本是D2。
- 最先定义原则: 如A->B->D1 , A->C->D2 , 那么最终项目A雨来的D的版本是D1.
dependencyManagement 节点,声明依赖项
dependencyManagement用来管理声明依赖项,最常见于spring boot项目中,在依赖节点只需要写groupId、artifactId就可以定位一个jar坐标,是因为spring boot的父pom中使用dependencyManagement声明了常用的依赖项,如:
-
<dependencyManagement>
-
<dependencies>
-
-
<dependency>
-
<groupId>org.springframework.bootgroupId>
-
<artifactId>spring-bootartifactId>
-
<version>1.5.7.RELEASEversion>
-
dependency>
-
.......
-
dependencies>
-
dependencyManagement>
使用dependencyManagement管理的依赖只是声明了,如果没有显示的定义在< dependencies >节点中是不生效的
profiles -> profile 节点,定义不同环境的构建属性
在软件项目迭代中,通常会有开发、测试、生产等不同的运行环境。很多时候不同的环境需要不同的依赖属性,诸如此场景,都可以使用profiles来定义不同环境下的变量,如:
-
<profiles>
-
<profile>
-
<id>devid>
-
<activation>
-
<activeByDefault>trueactiveByDefault>
-
activation>
-
<properties>
-
-
<sales.api.version>1.0-SNAPSHOTsales.api.version>
-
-
<logging.path>${basedir}/target/logslogging.path>
-
properties>
-
profile>
-
<profile>
-
<id>uatid>
-
<properties>
-
<sales.api.version>1.0-SNAPSHOTsales.api.version>
-
<logging.path>/data/logs/${appName}logging.path>
-
properties>
-
profile>
-
<profile>
-
<id>prodid>
-
<properties>
-
<sales.api.version>1.0-RELEASESsales.api.version>
-
<logging.path>/data/logs/${appName}logging.path>
-
properties>
-
profile>
-
profiles>
repositories、pluginRepositories 节点,定义依赖和插件的仓库地址
这里可以定义jar拉取的仓库地址,除了Apache中央仓库外,还有很多其他的开源仓库,如spring的,
-
<repositories>
-
<repository>
-
<id>centralid>
-
<name>Central Repositoryname>
-
<url>http://repo.maven.apache.org/maven2url>
-
<layout>defaultlayout>
-
<snapshots>
-
<enabled>falseenabled>
-
snapshots>
-
repository>
-
repositories>
-
-
<pluginRepositories>
-
<pluginRepository>
-
<id>centralid>
-
<name>Central Repositoryname>
-
<url>http://repo.maven.apache.org/maven2url>
-
<layout>defaultlayout>
-
<snapshots>
-
<enabled>falseenabled>
-
snapshots>
-
<releases>
-
<updatePolicy>neverupdatePolicy>
-
releases>
-
pluginRepository>
-
pluginRepositories>
构建信息
build 节点,设置输入输出路径
为什么在使用Maven构建的项目中,项目编译后会在pom所在目录下生成target目录?是因为在build构建节点中有如下的默认的配置。当然,如果你显示配置了如下的属性,就可以指定编译后文件的输出目录
-
<build>
-
<sourceDirectory>${basedir}/src/main/javasourceDirectory>
-
<scriptSourceDirectory>${basedir}/src/main/scriptsscriptSourceDirectory>
-
<testSourceDirectory>${basedir}/src/test/javatestSourceDirectory>
-
<outputDirectory>${basedir}/target/classesoutputDirectory>
-
<testOutputDirectory>${basedir}/target/test-classestestOutputDirectory>
-
...
-
build>
build -> resources,定义项目资源
resources用来定义项目的资源路径,默认的路径为${basedir}/src/main/resources,在spring boot环境中,继承了spring boot的父pom属性,它的resources定义如下:
-
<resources>
-
<resource>
-
<directory>${basedir}/src/main/resourcesdirectory>
-
<filtering>truefiltering>
-
<includes>
-
<include>**/application*.ymlinclude>
-
<include>**/application*.yamlinclude>
-
<include>**/application*.propertiesinclude>
-
includes>
-
resource>
-
<resource>
-
<directory>${basedir}/src/main/resourcesdirectory>
-
<excludes>
-
<exclude>**/application*.ymlexclude>
-
<exclude>**/application*.yamlexclude>
-
<exclude>**/application*.propertiesexclude>
-
excludes>
-
resource>
-
resources>
可以看到,spring boot中只定义了三种文件类型的资源,而且通配application开头的文件。当项目中有其他的文件类型或不是application开头时,Maven就会过滤掉。而且在spring boot中定义了属性占位符为@符号,所以在资源文件中使用${}时并不会生效。为了解决这个问题,可以自己在pom中定义resources属性覆盖父pom的行为:如,
-
<resources>
-
<resource>
-
<directory>src/main/resourcesdirectory>
-
<includes>
-
<include>**/*include>
-
includes>
-
<filtering>truefiltering>
-
resource>
-
resources>
build -> plugins -> plugin,定义构建插件
plugin这个节点主要用来定义构建的插件,包括自定义和已经发布到中央仓库的。如spring boot环境想构建可执行的jar需要添加spring-boot-maven-plugin插件。
-
-
<!扫描url-->
-
<plugin>
-
<groupId>com.yudianbank.plugingroupId>
-
<artifactId>api-abstractorartifactId>
-
<version>1.1.1-RELEASEversion>
-
<executions>
-
<execution>
-
<phase>process-classesphase>
-
<goals>
-
<goal>createAbstractgoal>
-
goals>
-
execution>
-
executions>
-
plugin>
-
<plugin>
-
<groupId>org.springframework.bootgroupId>
-
<artifactId>spring-boot-maven-pluginartifactId>
-
plugin>
-
plugins>
更多可用的插件:http://maven.apache.org/plugins/index.html
distributionManagement 节点,配置deploy的仓库地址
当我们自己搭建了私服,想要将jar包编译后上传到私服时,需要在这个节点配置仓库的地址,如:
-
<distributionManagement>
-
<repository>
-
<id>repoid>
-
<name>User Project Releasesname>
-
<url>http://192.168.1.204:8081/nexus/content/repositories/releasesurl>
-
repository>
-
<snapshotRepository>
-
<id>repoid>
-
<name>User Project SNAPSHOTSname>
-
<url>http://192.168.1.204:8081/nexus/content/repositories/snapshotsurl>
-
snapshotRepository>
-
distributionManagement>
项目信息
根节点下的name、description、url等节点
根节点下的name、description、url等节点用来描述项目的基本信息,如:
-
<name>salesname>
-
<description>这是一个销售系统description>
-
<url>http://www.kailing.puburl>
Licenses节点,描述许可证信息
-
<licenses>
-
<license>
-
<name>Apache License, Version 2.0name>
-
<url>https://www.apache.org/licenses/LICENSE-2.0.txturl>
-
<distribution>repodistribution>
-
<comments>A business-friendly OSS licensecomments>
-
license>
-
licenses>
Organization节点,描述组织信息
-
<organization>
-
<name>kekingname>
-
<url>http://www.keking.cnurl>
-
organization>
省略....
遵守的准则规范
Maven坐标version属性设置
一般建议在开发和测试环境中的jar,打成SNAPSHOT的,生产环境的版本打成RELEASES的,这个可以通过上面的profiles节点来控制,他们的区别如下:
- SNAPSHOT :当版本号带’-SNAPSHOT’后缀时,既定义发布的jar为快照版本,应用在依赖时,总是会拉取最新的快照版本。
- RELEASES :当版本号带’-RELEASES’后缀时,既定义发布的jar为发行版,应用依赖时,首次会从远程仓库拉取,当本地仓库已有时,就不会从远程仓库拉最新的依赖了。RELEASES版本的每次更新必须指定版本号。
开发中的api模块,需要deploy
应用有些模块需要提供给别人依赖,比如api模块、common模块等。在开发时,每次接口有变动时,记得mvn deploy下,把jar上传到私服。
依赖的jar的版本使用属性控制
建议依赖别的jar时,不要写死jar的版本,通过properties节点定义的属性来控制,那么当你pom被别人依赖时,上层pom可以通过定义属性值覆盖父pom中属性来控制依赖的版本
多模块项目时,模块命名规范
在多模块时,子模块的命名建议使用父模块作为前缀,如sales系统,api模块为sales-api,app模块为sales-app
附录,incubator-skywalking的Maven配置,提供参考
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0modelVersion> <groupId>org.apache.skywalkinggroupId> <artifactId>apmartifactId> <version>6.1.0-SNAPSHOTversion> <parent> <groupId>org.apachegroupId> <artifactId>apacheartifactId> <version>21version> parent> <modules> <module>oap-servermodule> <module>apm-commonsmodule> <module>apm-sniffermodule> <module>apm-application-toolkitmodule> <module>apm-protocolmodule> <module>apm-webappmodule> <module>apm-distmodule> <module>apm-checkstylemodule> modules> <packaging>pompackaging> <name>apmname> <url>https://github.com/apache/incubator-skywalkingurl> <scm> <url>https://github.com/apache/incubator-skywalkingurl> <connection>scm:git:https://github.com/apache/incubator-skywalking.gitconnection> <developerConnection>scm:git:https://github.com/apache/incubator-skywalking.gitdeveloperConnection> <tag>HEADtag> scm> <issueManagement> <system>GitHubsystem> <url>https://github.com/apache/incubator-skywalking/issuesurl> issueManagement> <licenses> <license> <name>The Apache Software License, Version 2.0name> <url>http://www.apache.org/licenses/LICENSE-2.0.txturl> license> licenses> <mailingLists> <mailingList> <name>SkyWalking Developer Listname> <post>[email protected]post> <subscribe>[email protected]subscribe> <unsubscribe>[email protected]unsubscribe> mailingList> <mailingList> <name>SkyWalking Commitsname> <post>[email protected]post> <subscribe>[email protected]subscribe> <unsubscribe>[email protected]unsubscribe> mailingList> mailingLists> <properties> <project.build.sourceEncoding>UTF-8project.build.sourceEncoding> <compiler.version>1.8compiler.version> <powermock.version>1.6.4powermock.version> <checkstyle.version>6.18checkstyle.version> <junit.version>4.12junit.version> <mockito-all.version>1.10.19mockito-all.version> <docker.plugin.version>0.4.13docker.plugin.version> <takari-maven-plugin.version>0.6.1takari-maven-plugin.version> <exec-maven-plugin.version>1.6.0exec-maven-plugin.version> <maven-antrun-plugin.version>1.8maven-antrun-plugin.version> <maven-deploy-plugin.version>2.8.2maven-deploy-plugin.version> <maven-assembly-plugin.version>3.1.0maven-assembly-plugin.version> <maven-failsafe-plugin.version>2.22.0maven-failsafe-plugin.version> <maven-surefire-plugin.version>2.22.0maven-surefire-plugin.version> <maven-jar-plugin.version>3.1.0maven-jar-plugin.version> <maven-shade-plugin.version>3.1.1maven-shade-plugin.version> <maven-enforcer-plugin.version>3.0.0-M2maven-enforcer-plugin.version> <apache-rat-plugin.version>0.12apache-rat-plugin.version> <maven-compiler-plugin.version>3.8.0maven-compiler-plugin.version> <maven-resource-plugin.version>3.1.0maven-resource-plugin.version> <maven-source-plugin.version>3.0.1maven-source-plugin.version> <versions-maven-plugin.version>2.5versions-maven-plugin.version> <coveralls-maven-plugin.version>4.3.0coveralls-maven-plugin.version> <maven-checkstyle-plugin.version>3.0.0maven-checkstyle-plugin.version> <jacoco-maven-plugin.version>0.8.3jacoco-maven-plugin.version> properties> <dependencies> <dependency> <groupId>junitgroupId> <artifactId>junitartifactId> <scope>testscope> dependency> <dependency> <groupId>org.mockitogroupId> <artifactId>mockito-allartifactId> <scope>testscope> dependency> <dependency> <groupId>org.powermockgroupId> <artifactId>powermock-module-junit4artifactId> <scope>testscope> dependency> <dependency> <groupId>org.powermockgroupId> <artifactId>powermock-api-mockitoartifactId> <scope>testscope> dependency> dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>junitgroupId> <artifactId>junitartifactId> <version>${junit.version}version> <scope>testscope> dependency> <dependency> <groupId>org.mockitogroupId> <artifactId>mockito-allartifactId> <version>${mockito-all.version}version> <scope>testscope> dependency> <dependency> <groupId>org.powermockgroupId> <artifactId>powermock-module-junit4artifactId> <version>${powermock.version}version> <scope>testscope> dependency> <dependency> <groupId>org.powermockgroupId> <artifactId>powermock-api-mockitoartifactId> <version>${powermock.version}version> <scope>testscope> dependency> dependencies> dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojogroupId> <artifactId>exec-maven-pluginartifactId> <executions> <execution> <id>git submodule updateid> <phase>initializephase> <inherited>falseinherited> <configuration> <executable>gitexecutable> <arguments> <argument>submoduleargument> <argument>updateargument> <argument>--initargument> <argument>--recursiveargument> arguments> configuration> <goals> <goal>execgoal> goals> execution> executions> plugin> <plugin> <groupId>io.takarigroupId> <artifactId>mavenartifactId> <version>${takari-maven-plugin.version}version> plugin> <plugin> <groupId>org.codehaus.mojogroupId> <artifactId>exec-maven-pluginartifactId> <version>${exec-maven-plugin.version}version> plugin> <plugin> <artifactId>maven-antrun-pluginartifactId> <version>${maven-antrun-plugin.version}version> plugin> <plugin> <artifactId>maven-deploy-pluginartifactId> <version>${maven-deploy-plugin.version}version> plugin> <plugin> <artifactId>maven-assembly-pluginartifactId> <version>${maven-assembly-plugin.version}version> plugin> <plugin> <artifactId>maven-failsafe-pluginartifactId> <version>${maven-failsafe-plugin.version}version> plugin> <plugin> <artifactId>maven-surefire-pluginartifactId> <version>${maven-surefire-plugin.version}version> plugin> <plugin> <artifactId>maven-jar-pluginartifactId> <version>${maven-jar-plugin.version}version> plugin> <plugin> <artifactId>maven-shade-pluginartifactId> <version>${maven-shade-plugin.version}version> plugin> plugins> pluginManagement> <plugins> <plugin> <artifactId>maven-enforcer-pluginartifactId> <version>${maven-enforcer-plugin.version}version> <executions> <execution> <id>enforce-javaid> <goals> <goal>enforcegoal> goals> <configuration> <rules> <requireJavaVersion> <version>[1.8,9)version> requireJavaVersion> rules> configuration> execution> executions> plugin> <plugin> <groupId>org.apache.ratgroupId> <artifactId>apache-rat-pluginartifactId> <version>${apache-rat-plugin.version}version> <configuration> <excludes> <exclude>**/target/**exclude> <exclude>**/DISCLAIMERexclude> <exclude>**/licenses/**exclude> <exclude>**/ui-licenses/**exclude> <exclude>**/codeStyle.xmlexclude> <exclude>**/*.imlexclude> <exclude>**/.idea/**exclude> <exclude>**/*.classpathexclude> <exclude>**/.projectexclude> <exclude>**/.settings/**exclude> <exclude>**/dependency-reduced-pom.xmlexclude> <exclude>**/skywalking-ui/.editorconfigexclude> <exclude>**/skywalking-ui/.webpackrc.jsexclude> <exclude>**/skywalking-ui/.roadhogrc.mock.jsexclude> <exclude>**/skywalking-ui/jest.config.jsexclude> <exclude>**/skywalking-ui/.eslintrc.jsexclude> <exclude>**/skywalking-ui/.stylelintrcexclude> <exclude>**/skywalking-ui/.prettierignoreexclude> <exclude>**/skywalking-ui/.prettierrcexclude> <exclude>**/skywalking-ui/public/font/iconfont/**exclude> <exclude>**/.gitignoreexclude> <exclude>**/.gitmodulesexclude> <exclude>**/.git/**exclude> <exclude>**/.travis.ymlexclude> <exclude>**/.github/**exclude> <exclude>**/*.mdexclude> <excldue>**/*.MDexcldue> <exclude>**/*.txtexclude> <exclude>**/docs/**exclude> <exclude>**/src/test/resources/json/*.jsonexclude> <exclude>**/skywalking-ui/node_modules/**exclude> <exclude>**/skywalking-ui/node/**exclude> <exclude>**/skywalking-ui/dist/**exclude> <exclude>skywalking-ui/package.jsonexclude> <exclude>skywalking-ui/package-lock.jsonexclude> <exclude>**/src/main/proto/gogoproto/gogo.protoexclude> <exclude>**/src/main/proto/envoy/**exclude> <exclude>**/src/main/proto/google/protobuf/*.protoexclude> <exclude>**/src/main/proto/prometheus/client_model/metrics.protoexclude> <exclude>**/src/main/proto/validate/validate.protoexclude> <exclude>**/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALLexer.tokensexclude> <exclude>.mvn/wrapper/maven-wrapper.propertiesexclude> excludes> configuration> <executions> <execution> <phase>verifyphase> <goals> <goal>checkgoal> goals> execution> executions> plugin> <plugin> <artifactId>maven-compiler-pluginartifactId> <version>${maven-compiler-plugin.version}version> <configuration> <source>${compiler.version}source> <target>${compiler.version}target> <encoding>${project.build.sourceEncoding}encoding> configuration> plugin> <plugin> <artifactId>maven-resources-pluginartifactId> <version>${maven-resource-plugin.version}version> <configuration> <encoding>${project.build.sourceEncoding}encoding> configuration> plugin> <plugin> <groupId>com.spotifygroupId> <artifactId>docker-maven-pluginartifactId> <version>${docker.plugin.version}version> <configuration> <skipDocker>trueskipDocker> configuration> plugin> <plugin> <artifactId>maven-source-pluginartifactId> <version>${maven-source-plugin.version}version> <executions> <execution> <id>attach-sourcesid> <phase>nonephase> <goals> <goal>jargoal> goals> execution> executions> plugin> <plugin> <groupId>org.codehaus.mojogroupId> <artifactId>versions-maven-pluginartifactId> <version>${versions-maven-plugin.version}version> plugin> <plugin> <groupId>org.eluder.coverallsgroupId> <artifactId>coveralls-maven-pluginartifactId> <version>${coveralls-maven-plugin.version}version> <configuration> <repoToken>xFwR2GqmxcMxV7tGEpW2NfwIrbCD4cQCSrepoToken> <sourceDirectories> <sourceDirectory>${project.build.sourceDirectory}sourceDirectory> sourceDirectories> configuration> plugin> <plugin> <groupId>org.jacocogroupId> <artifactId>jacoco-maven-pluginartifactId> <version>${jacoco-maven-plugin.version}version> <executions> <execution> <id>prepare-agentid> <goals> <goal>prepare-agentgoal> goals> execution> executions> plugin> <plugin> <artifactId>maven-checkstyle-pluginartifactId> <version>${maven-checkstyle-plugin.version}version> <dependencies> <dependency> <groupId>org.apache.skywalkinggroupId> <artifactId>apm-checkstyleartifactId> <version>5.0.0-betaversion> dependency> <dependency> <groupId>com.puppycrawl.toolsgroupId> <artifactId>checkstyleartifactId> <version>8.11version> dependency> dependencies> <executions> <execution> <id>validateid> <phase>validatephase> <configuration> <configLocation>skywalking/checkStyle.xmlconfigLocation> <headerLocation>skywalking/CHECKSTYLE_HEADheaderLocation> <encoding>UTF-8encoding> <consoleOutput>trueconsoleOutput> <includeTestSourceDirectory>trueincludeTestSourceDirectory> <failsOnError>truefailsOnError> <excludes>org.apache.skywalking.apm/network/**/*.java, org.apache.skywalking.apm/collector/remote/grpc/**/*.java, org.apache.skywalking.apm/agent/core/context/ids/base64/*.java excludes> configuration> <goals> <goal>checkgoal> goals> execution> executions> plugin> plugins> build> project>
https://blog.csdn.net/weixin_34290000/article/details/89539283