项目组准备将Kubernetes升级到1.6版本,然而项目使用的fabric8的kubernetes-client对1.6版本支持的还不到位,比如说当前不支持使用batch/v1的api来创建Job,所以只能自己改源码来实现。虽然代码改的很快,但是最后在修改pom.xm,以及上传到Maven私仓的过程中,却耗费了很长的时间。对于这种多级Maven工程的代码,到现在依然有很多疑惑。趁着这次事件,对Maven又更熟悉了一些,所以做一些笔记,留待以后阅读。
安装
- 官网:http://maven.apache.org/
- 下载:http://maven.apache.org/download.cgi
- 安装:http://maven.apache.org/install.html
前提:
JAVA环境,JAVA_HOME已配置
安装包:
apache-maven-3.3.9-bin.zip
安装步骤:
- 解压安装包;
- 将 apache-maven-3.3.9的bin目录添加到PATH环境变量中;如果是linux,
export PATH=/opt/apache-maven-3.3.9/bin:$PATH
;
验证:
在命令行使用 mvn -v进行确认,结果应如下图:
$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: D:\apache-maven-3.3.9
Java version: 1.8.0_74, vendor: Oracle Corporation
Java home: D:\Program Files (x86)\Java\jdk1.8.0_74\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
常用命令
1. mvn clean
清理产生的项目
2. mvn compile
编译源代码
3. mvn test-compile
编译测试代码
4. mvn package
打包
5. mvn jar:jar
打jar包
6. mvn install
在本地仓库中安装jar包
7. mvn checkstyle:checkstyle
检查代码的样式是否符合规范,规范可以在pom.xml中自定义,比如是否存在没有使用的import等。
8. mvn test
运行测试
9. -Dmaven.test.skip=true
跳过测试
10. mvn deploy
直接mvn deploy
会根据pom.xml里的distributionManagement与setting.xml里的servers来指定maven私仓以及认证信息,会将所有的jar包、依赖关系、test结果都上传到maven仓库。可以结合-Dmaven.test.skip=true
使用,来跳过test过程。
<distributionManagement>
<repository>
<id>user-release</id>
<url>http://nexus.dis.sohucs.com/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>user-snapshot</id>
<url>http://nexus.dis.sohucs.com/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<server>
<id>user-release</id>
<username>deployment</username>
<password>deploymentsohu</password>
</server>
<server>
<id>user-plugin</id>
<username>deployment</username>
<password>deploymentsohu</password>
</server>
<server>
<id>user-snapshot</id>
<username>deployment</username>
<password>deploymentsohu</password>
</server>
也可以上传指定单个jar包:
mvn deploy:deploy-file -DgroupId=org.domeos -DartifactId=kubernetes-client -Dversion=2.3.1 -Dpackaging=jar -Durl=http://nexus.dis.sohucs.com/content/repositories/releases/ -DrepositoryId=user-release -Dfile=target/kubernetes-client-2.3.1.jar
-DgroupId
和-DartifactId
构成了jar包在pom.xml的坐标。-Dfile
用来指定jar包在本地的绝对路径。-Durl
用来指定maven私仓的位置,打开nexus-->repositories菜单,可以看到该路径。-DrepositoryId
用来指定repository id,在nexus的configuration可以看到,一般setting.xml里的servers中的各个server的id与repository id是一致的,所以也可以setting.xml中确定。-Dversion
用来指定jar包本信息。
问题汇总
1. [ERROR] No implementation for org.eclipse.aether.RepositorySystem was bound.
错误信息:
[ERROR] 1) No implementation for org.eclipse.aether.RepositorySystem was bound.
[ERROR] while locating ru.yandex.qatools.allure.report.AllureReportMojo
[ERROR] at ClassRealm[plugin>ru.yandex.qatools.allure:allure-maven-plugin:2.0, parent: ClassRealm[plugin>org.apache.maven.plugins:maven-site-plugin:3.0, parent: sun.misc.Launcher$AppClassLoader@6d06d69c]]
[ERROR] while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=ru.yandex.qatools.allure:allure-maven-plugin:2.0:report)
[ERROR]
[ERROR] 1 error
[ERROR] role: org.apache.maven.plugin.Mojo
[ERROR] roleHint: ru.yandex.qatools.allure:allure-maven-plugin:2.0:report
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
原因:
allure-maven-plugin需要在3.1.1以上的版本才能使用。
也许Maven版本太低,也许使用的是IDEA 14,而IDEA 14集成的Maven版本是3.0.5,所以版本还是太低。
解决办法:
将Maven升级到3.1.1以上的版本。