maven本地配置
maven仓库配置
修改maven/conf/settings.xml文件,把仓库配置成本地仓库
<localRepository>repository</localRepository>
在maven/conf/settings.xml.文件添加获取jar包的地址
<mirror> <id>proxied-releases</id> <name>Release Mirror</name> <url>https://www.test.test/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
id、name随意添加,不影响
url值为公司maven私服地址或阿里maven地址
Jenkins配置maven
jenkins maven setting.xml文件配置
打开Jenkins设置下的全局工具设置,配置如下,文件路径为本地 maven setting.xml 文件路径
Name为maven版本,MAVEN_HOME 为maven安装路径
Jenkins项目任务配置
构建配置
Root POM:拉取项目代码的 pom.xml 文件
Goals and options:构建所使用的命令 命令解析:clean -PQA -DskipTests package install:清除旧项目后使用配置文件中的QA配置进行打包target下的jar安装到本地仓库 clean:clean有两种 maven clean:maven clean是maven的一个清洁生命周期,目的是删除build目录下的构建输出,体现在文件系统上是删除了Target目录所有文件,包括该目录 project clean:project clean是IDE对已经生成的class文件的删除操作,体现在文件系统上是只删除了Target目录中classes文件夹中所有内容 mvn package -Pqa -DskipTests package :基本命令,进行打包 -Pqa:项目开发需要有多个环境,一般为开发,测试,预发布,正式4个环境,通过maven可以实现按不同环境进行打包部署。也就是dev(开发)、qa(测试)、pre(预发)、生产正式(prod)四个环境,对应的都有各自的配置文件properties。 通过 -P 传入环境id参数就可以选择环境,比如传入 qa,即命令 -Pqa 。会得到 qa.peroperties 配置文件,这是因为在 pom.xml 文件中有这样的配置
<profiles> <!-- 默认 --> <profile> <id>dev</id> <properties> <profile.active>dev</profile.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <!-- 质检 --> <profile> <id>QA</id> <properties> <profile.active>QA</profile.active> </properties> </profile> <!-- 生产 --> <profile> <id>pro</id> <properties> <profile.active>pro</profile.active> </properties> </profile> </profiles>
<build> <filters> <filter>src/main/resources/env/${env}.properties</filter> </filters> <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> </includes> </resource> </resources> .... </build>
其中${env}.properties就是让我们传入环境参数qa、dev、prod、pre。
- DskipTests:跳过测试,否则打包过程很慢
打包上传启动
执行shell
jenkins和项目服务在一台服务器上,所以不用跨服务器传包,都是本地拷贝,推荐这种方式,打包项目贼快