# Maven 工程构建
# 安装
- 安装 maven3.x ,下载 (opens new window) zip后,直接解压,在环境变量path中加上路径,如.
E:\apache-maven-3.6.3\bin
cmd
运行mvn -version
看是否显示版本则成功,比较简单~- 查看
maven
运行命令
# 打包
// 到根目录下,执行mvn命令
mvn package
// 或
mvn install -Denforcer.fail=false -DskipTests
# 打包异常:
# 异常1:
Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce (enforce-maven-version) on project spring-data-jpa: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
所以针对这个问题,如下方案:
- 方案一:调整本地环境满足当前的插件约束,比如楼主这里只需要升级本地的maven版本到3.5.0及以上即可解决问题
- 方案二:跳过enforcer的强制约束,在构建的命令加上跳过的指令,如:
mvn install -Denforcer.skip=true
- 方案三:设置规则校验失败不影响构建流程,在构建的命令上加指令,如:
mvn install -Denforcer.fail=false
# 异常2:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project dingding-notifications: There are test failures.
方案:关键字跳过测试:-DskipTests
;
执行: mvn install -Denforcer.fail=false -DskipTests
# 异常3:
@Getter和@Setter注解,工具上面显示错误,安装新的插件,下载后点击jar;退出安装后,重新打开即可解决
Eclipse下无法解析注解:@Getter和@Setter - 不想下火车的人 - 博客园 (cnblogs.com) (opens new window)
# 异常4:
解决Maven出现Plugin execution not covered by lifecycle configuration 错误
进入【Window】-【Preferences】-【Maven】-【Lifecycle Mapping】
查看是否存在
lifecycle-mapping-metadata.xml
文件,如果不存在时,先去Eclipse的安装目录下的
plugins
下的org.eclipse.m2e.lifecyclemapping.defaults_xxxxxx.jar文件中找到该文件并解压,找到lifecycle-mapping-metadata.xml
文件;拷贝到工作空间的路径下E:\eclipse-workspace\.metadata\.plugins\org.eclipse.m2e.core
如果不存在,去google、baidu找到对应的
jar
或xml
文件进行下载保存下来,再拷贝到对应目录下;编辑
lifecycle-mapping-metadata.xml
文件错误案例:
# 1. Plugin execution not covered by lifecycle configuration:
org.codehaus.gmavenplus
:gmavenplus-plugin
:1.12.1
:addTestSources
(execution: test-in-groovy, phase: initialize)、# 2. Plugin execution not covered by lifecycle configuration:
org.jenkins-ci.tools
:maven-hpi-plugin
:3.16
:validate-hpi
(execution: default-validate-hpi, phase: validate)<!-- 案例增加插件模板 --> <!--1. org.codehaus.gmavenplus:gmavenplus-plugin:1.12.1:addTestSources (execution: test-in-groovy, phase: initialize) --> <pluginExecution> <pluginExecutionFilter> <groupId>org.codehaus.gmavenplus</groupId> <artifactId>gmavenplus-plugin</artifactId> <versionRange>[1.12.1,)</versionRange> <goals> <goal>addTestSources</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> <!--2. org.jenkins-ci.tools:maven-hpi-plugin:3.16:validate-hpi (execution: default-validate-hpi, phase: validate) --> <pluginExecution> <pluginExecutionFilter> <groupId>org.jenkins-ci.tools</groupId> <artifactId>maven-hpi-plugin</artifactId> <versionRange>[3.16,)</versionRange> <goals> <goal>validate-hpi</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution>
主要是
groupId
、artifactId
、versionRange
、goal
这四个属性对应的值要和系统报错的值 设置成一样, 加入到lifecycle-mapping-metadata.xml
文件中即可;
# 异常5:
[ERROR] Some problems were encountered while processing the POMs:
父工程添加jar包后需要先在父工程依次:右键
-> run as
-> maven install