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.project</groupId> //组织ID
- <artifactId>salesAppParent</artifactId>//工程名称
- <packaging>pom</packaging>//打包方式,如:jar、war、pom、rar等
- <version>1.0-RELEASES</version> //版本号
由groupId、artifactId、version三个元素定位唯一的jar信息,常说的发个Maven坐标也就是这三个元素
modules 节点,聚合子模块,
在多模块的项目中使用,用来定义子模块,一般多模块项目中,父模块的packaging都定义为pom
- <modules>
- <module>api</module>
- <module>producer</module>
- </modules>
parent节点,继承其他pom模型的属性
如:在spring boot项目中,会有如下parent节点,用来继承spring boot已经定义好的pom
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.7.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
properties 节点,定义属性信息
这个节点一般用于定义一些属性,用来作为插件的默认值。在这里定义的属性可以贯穿Maven build的整个生命周期,Maven属性是值占位符,可以在pom中通过${XXX}符号来使用
- <properties>
- <spring-cloud.version>Dalston.SR3</spring-cloud.version>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <compiler.version>1.8</compiler.version>
- <powermock.version>1.6.4</powermock.version>
- <checkstyle.version>6.18</checkstyle.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.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <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.public</groupId>
- <artifactId>pdf</artifactId>
- <version>1.1-RELEASES</version>
- <exclusions>
- <exclusion>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- </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>
- <!-- Spring Boot -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot</artifactId>
- <version>1.5.7.RELEASE</version>
- </dependency>
- .......
- </dependencies>
- </dependencyManagement>
使用dependencyManagement管理的依赖只是声明了,如果没有显示的定义在< dependencies >节点中是不生效的
profiles -> profile 节点,定义不同环境的构建属性
在软件项目迭代中,通常会有开发、测试、生产等不同的运行环境。很多时候不同的环境需要不同的依赖属性,诸如此场景,都可以使用profiles来定义不同环境下的变量,如:
- <profiles>
- <profile>
- <id>dev</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <properties>
- <!--销售平台 api版本-->
- <sales.api.version>1.0-SNAPSHOT</sales.api.version>
- <!--本地日志存储地址-->
- <logging.path>${basedir}/target/logs</logging.path>
- </properties>
- </profile>
- <profile>
- <id>uat</id>
- <properties>
- <sales.api.version>1.0-SNAPSHOT</sales.api.version>
- <logging.path>/data/logs/${appName}</logging.path>
- </properties>
- </profile>
- <profile>
- <id>prod</id>
- <properties>
- <sales.api.version>1.0-RELEASES</sales.api.version>
- <logging.path>/data/logs/${appName}</logging.path>
- </properties>
- </profile>
- </profiles>
repositories、pluginRepositories 节点,定义依赖和插件的仓库地址
这里可以定义jar拉取的仓库地址,除了Apache*仓库外,还有很多其他的开源仓库,如spring的,
- <repositories>
- <repository>
- <id>central</id>
- <name>Central Repository</name>
- <url>http://repo.maven.apache.org/maven2</url>
- <layout>default</layout>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>central</id>
- <name>Central Repository</name>
- <url>http://repo.maven.apache.org/maven2</url>
- <layout>default</layout>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- <releases>
- <updatePolicy>never</updatePolicy>
- </releases>
- </pluginRepository>
- </pluginRepositories>
构建信息
build 节点,设置输入输出路径
为什么在使用Maven构建的项目中,项目编译后会在pom所在目录下生成target目录?是因为在build构建节点中有如下的默认的配置。当然,如果你显示配置了如下的属性,就可以指定编译后文件的输出目录
- <build>
- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
- <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
- <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
- <outputDirectory>${basedir}/target/classes</outputDirectory>
- <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
- ...
- </build>
build -> resources,定义项目资源
resources用来定义项目的资源路径,默认的路径为${basedir}/src/main/resources,在spring boot环境中,继承了spring boot的父pom属性,它的resources定义如下:
- <resources>
- <resource>
- <directory>${basedir}/src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/application*.yml</include>
- <include>**/application*.yaml</include>
- <include>**/application*.properties</include>
- </includes>
- </resource>
- <resource>
- <directory>${basedir}/src/main/resources</directory>
- <excludes>
- <exclude>**/application*.yml</exclude>
- <exclude>**/application*.yaml</exclude>
- <exclude>**/application*.properties</exclude>
- </excludes>
- </resource>
- </resources>
可以看到,spring boot中只定义了三种文件类型的资源,而且通配application开头的文件。当项目中有其他的文件类型或不是application开头时,Maven就会过滤掉。而且在spring boot中定义了属性占位符为@符号,所以在资源文件中使用${}时并不会生效。为了解决这个问题,可以自己在pom中定义resources属性覆盖父pom的行为:如,
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <includes>
- <include>**/*</include>
- </includes>
- <filtering>true</filtering>
- </resource>
- </resources>
build -> plugins -> plugin,定义构建插件
plugin这个节点主要用来定义构建的插件,包括自定义和已经发布到*仓库的。如spring boot环境想构建可执行的jar需要添加spring-boot-maven-plugin插件。
- <plugins>
- <!扫描url-->
- <plugin>
- <groupId>com.yudianbank.plugin</groupId>
- <artifactId>api-abstractor</artifactId>
- <version>1.1.1-RELEASE</version>
- <executions>
- <execution>
- <phase>process-classes</phase>
- <goals>
- <goal>createAbstract</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
更多可用的插件:http://maven.apache.org/plugins/index.html
distributionManagement 节点,配置deploy的仓库地址
当我们自己搭建了私服,想要将jar包编译后上传到私服时,需要在这个节点配置仓库的地址,如:
- <distributionManagement>
- <repository>
- <id>repo</id>
- <name>User Project Releases</name>
- <url>http://192.168.1.204:8081/nexus/content/repositories/releases</url>
- </repository>
- <snapshotRepository>
- <id>repo</id>
- <name>User Project SNAPSHOTS</name>
- <url>http://192.168.1.204:8081/nexus/content/repositories/snapshots</url>
- </snapshotRepository>
- </distributionManagement>
项目信息
根节点下的name、description、url等节点
根节点下的name、description、url等节点用来描述项目的基本信息,如:
- <name>sales</name>
- <description>这是一个销售系统</description>
- <url>http://www.kailing.pub</url>
Licenses节点,描述许可证信息
- <licenses>
- <license>
- <name>Apache License, Version 2.0</name>
- <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
- <distribution>repo</distribution>
- <comments>A business-friendly OSS license</comments>
- </license>
- </licenses>
Organization节点,描述组织信息
- <organization>
- <name>keking</name>
- <url>http://www.keking.cn</url>
- </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.0</modelVersion> <groupId>org.apache.skywalking</groupId> <artifactId>apm</artifactId> <version>6.1.0-SNAPSHOT</version> <parent> <groupId>org.apache</groupId> <artifactId>apache</artifactId> <version>21</version> </parent> <modules> <module>oap-server</module> <module>apm-commons</module> <module>apm-sniffer</module> <module>apm-application-toolkit</module> <module>apm-protocol</module> <module>apm-webapp</module> <module>apm-dist</module> <module>apm-checkstyle</module> </modules> <packaging>pom</packaging> <name>apm</name> <url>https://github.com/apache/incubator-skywalking</url> <scm> <url>https://github.com/apache/incubator-skywalking</url> <connection>scm:git:https://github.com/apache/incubator-skywalking.git</connection> <developerConnection>scm:git:https://github.com/apache/incubator-skywalking.git</developerConnection> <tag>HEAD</tag> </scm> <issueManagement> <system>GitHub</system> <url>https://github.com/apache/incubator-skywalking/issues</url> </issueManagement> <licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> </license> </licenses> <mailingLists> <mailingList> <name>SkyWalking Developer List</name> <post>dev@skywalking.incubator.apache.org</post> <subscribe>dev-subscribe@skywalking.incubator.apache.org</subscribe> <unsubscribe>dev-unsubscribe@skywalking.incubator.apache.org</unsubscribe> </mailingList> <mailingList> <name>SkyWalking Commits</name> <post>commits@skywalking.incubator.apache.org</post> <subscribe>commits-subscribe@skywalking.incubator.apache.org</subscribe> <unsubscribe>commits-unsubscribe@skywalking.incubator.apache.org</unsubscribe> </mailingList> </mailingLists> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <compiler.version>1.8</compiler.version> <powermock.version>1.6.4</powermock.version> <checkstyle.version>6.18</checkstyle.version> <junit.version>4.12</junit.version> <mockito-all.version>1.10.19</mockito-all.version> <!-- Plugin versions --> <docker.plugin.version>0.4.13</docker.plugin.version> <takari-maven-plugin.version>0.6.1</takari-maven-plugin.version> <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version> <maven-antrun-plugin.version>1.8</maven-antrun-plugin.version> <maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version> <maven-assembly-plugin.version>3.1.0</maven-assembly-plugin.version> <maven-failsafe-plugin.version>2.22.0</maven-failsafe-plugin.version> <maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version> <maven-jar-plugin.version>3.1.0</maven-jar-plugin.version> <maven-shade-plugin.version>3.1.1</maven-shade-plugin.version> <maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version> <apache-rat-plugin.version>0.12</apache-rat-plugin.version> <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> <maven-resource-plugin.version>3.1.0</maven-resource-plugin.version> <maven-source-plugin.version>3.0.1</maven-source-plugin.version> <versions-maven-plugin.version>2.5</versions-maven-plugin.version> <coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version> <maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version> <jacoco-maven-plugin.version>0.8.3</jacoco-maven-plugin.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>${mockito-all.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>${powermock.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>${powermock.version}</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <id>git submodule update</id> <phase>initialize</phase> <inherited>false</inherited> <configuration> <executable>git</executable> <arguments> <argument>submodule</argument> <argument>update</argument> <argument>--init</argument> <argument>--recursive</argument> </arguments> </configuration> <goals> <goal>exec</goal> </goals> </execution> </executions> </plugin> <!-- mvn -N io.takari:maven:wrapper -Dmaven=3.5.4 --> <plugin> <groupId>io.takari</groupId> <artifactId>maven</artifactId> <version>${takari-maven-plugin.version}</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>${exec-maven-plugin.version}</version> </plugin> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>${maven-antrun-plugin.version}</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>${maven-deploy-plugin.version}</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>${maven-assembly-plugin.version}</version> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>${maven-failsafe-plugin.version}</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>${maven-surefire-plugin.version}</version> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>${maven-jar-plugin.version}</version> </plugin> <plugin> <artifactId>maven-shade-plugin</artifactId> <version>${maven-shade-plugin.version}</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-enforcer-plugin</artifactId> <version>${maven-enforcer-plugin.version}</version> <executions> <execution> <id>enforce-java</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireJavaVersion> <!-- Build has not yet been updated for Java 9+ --> <version>[1.8,9)</version> </requireJavaVersion> </rules> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> <version>${apache-rat-plugin.version}</version> <configuration> <excludes> <exclude>**/target/**</exclude> <exclude>**/DISCLAIMER</exclude> <exclude>**/licenses/**</exclude> <exclude>**/ui-licenses/**</exclude> <exclude>**/codeStyle.xml</exclude> <!-- IDE files --> <exclude>**/*.iml</exclude> <exclude>**/.idea/**</exclude> <exclude>**/*.classpath</exclude> <exclude>**/.project</exclude> <exclude>**/.settings/**</exclude> <exclude>**/dependency-reduced-pom.xml</exclude> <!-- UI IDE configs --> <exclude>**/skywalking-ui/.editorconfig</exclude> <!-- UI Compiler configs --> <exclude>**/skywalking-ui/.webpackrc.js</exclude> <exclude>**/skywalking-ui/.roadhogrc.mock.js</exclude> <!-- UI Test configs --> <exclude>**/skywalking-ui/jest.config.js</exclude> <!-- UI style check files --> <exclude>**/skywalking-ui/.eslintrc.js</exclude> <exclude>**/skywalking-ui/.stylelintrc</exclude> <exclude>**/skywalking-ui/.prettierignore</exclude> <exclude>**/skywalking-ui/.prettierrc</exclude> <!-- UI icon files --> <exclude>**/skywalking-ui/public/font/iconfont/**</exclude> <!-- git files --> <exclude>**/.gitignore</exclude> <exclude>**/.gitmodules</exclude> <exclude>**/.git/**</exclude> <!-- CI files --> <exclude>**/.travis.yml</exclude> <!-- GitHub files --> <exclude>**/.github/**</exclude> <!-- document files --> <exclude>**/*.md</exclude> <excldue>**/*.MD</excldue> <exclude>**/*.txt</exclude> <exclude>**/docs/**</exclude> <!-- Test cases data in JSON format --> <exclude>**/src/test/resources/json/*.json</exclude> <!-- front end libary and generated files --> <exclude>**/skywalking-ui/node_modules/**</exclude> <exclude>**/skywalking-ui/node/**</exclude> <exclude>**/skywalking-ui/dist/**</exclude> <!-- web UI dependencies descriptions --> <exclude>skywalking-ui/package.json</exclude> <exclude>skywalking-ui/package-lock.json</exclude> <!-- Proto files of Istio, envoy, prometheus and gogoproto projects --> <exclude>**/src/main/proto/gogoproto/gogo.proto</exclude> <exclude>**/src/main/proto/envoy/**</exclude> <exclude>**/src/main/proto/google/protobuf/*.proto</exclude> <exclude>**/src/main/proto/prometheus/client_model/metrics.proto</exclude> <exclude>**/src/main/proto/validate/validate.proto</exclude> <!-- generated file from antlr --> <exclude>**/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALLexer.tokens</exclude> <!-- Maven Wrapper generated files --> <exclude>.mvn/wrapper/maven-wrapper.properties</exclude> </excludes> </configuration> <executions> <execution> <phase>verify</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <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-plugin</artifactId> <version>${maven-resource-plugin.version}</version> <configuration> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker.plugin.version}</version> <configuration> <skipDocker>true</skipDocker> </configuration> </plugin> <plugin> <!-- 源码插件 --> <artifactId>maven-source-plugin</artifactId> <version>${maven-source-plugin.version}</version> <!-- 发布时自动将源码同时发布的配置 --> <executions> <execution> <id>attach-sources</id> <phase>none</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId> <version>${versions-maven-plugin.version}</version> </plugin> <plugin> <groupId>org.eluder.coveralls</groupId> <artifactId>coveralls-maven-plugin</artifactId> <version>${coveralls-maven-plugin.version}</version> <configuration> <repoToken>xFwR2GqmxcMxV7tGEpW2NfwIrbCD4cQCS</repoToken> <sourceDirectories> <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> </sourceDirectories> </configuration> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco-maven-plugin.version}</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-checkstyle-plugin</artifactId> <version>${maven-checkstyle-plugin.version}</version> <dependencies> <dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-checkstyle</artifactId> <version>5.0.0-beta</version> </dependency> <dependency> <groupId>com.puppycrawl.tools</groupId> <artifactId>checkstyle</artifactId> <version>8.11</version> </dependency> </dependencies> <executions> <execution> <id>validate</id> <phase>validate</phase> <configuration> <configLocation>skywalking/checkStyle.xml</configLocation> <headerLocation>skywalking/CHECKSTYLE_HEAD</headerLocation> <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <includeTestSourceDirectory>true</includeTestSourceDirectory> <failsOnError>true</failsOnError> <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>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
https://blog.csdn.net/weixin_34290000/article/details/89539283