Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1051494
  • 博文数量: 155
  • 博客积分: 5339
  • 博客等级: 大校
  • 技术积分: 1436
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-10 21:41
文章分类

全部博文(155)

文章存档

2016年(3)

2015年(7)

2014年(3)

2013年(1)

2012年(8)

2011年(5)

2010年(1)

2009年(5)

2008年(4)

2007年(26)

2006年(46)

2005年(46)

分类: Java

2016-04-27 17:41:18

1.jenkins部署【linux环境】
下载最新的jenkins-1.651.1-1.1.noarch.rpm,并安装
rpm -iv jenkins-1.651.1-1.1.noarch.rpm
启动jenkins
service jenkins start

2.下载apache-maven-3.3.9-bin.tar.gz、ant 并解压

3.通过浏览器登录并配置
浏览器登录,默认访问端口是8080

系统管理-》系统设置
(1)设置JDK路径
(2)设置Ant
(3)设置Maven路径

4.添加插件
系统管理-》管理插件-》可选插件
安装插件及相关的依赖插件:
FindBugs Plug-in
Checkstyle Plug-in
PMD Plug-in
Static Analysis Collector Plug-in
Dashboard View
Matrix Project Plugin

##安装插件过程中可以需要翻墙,可以通过系统管理-》管理插件-》高级,配置代理

5.创建项目
新建,选择“构建一个自由风格的软件项目”
配置Subversion,项目url地址、用户名、密码
配置构建触发器,选择Poll SCM,设置定时器:@hourly(可随意指定)
构建,选择Maven版本,Goals提前设置为:“compile findbugs:findbugs checkstyle:checkstyle pmd:pmd”
构建后,增加Checkstyle results 、FindBugs results、PMD results,配置结果路径:**/checkstyle-result.xml、**/findbugsXml.xml、**/pmd.xml
最后增加Publish combined analysis results,选择Checkstyle warnings、FindBugs warnings、PMD warnings

存档构建后生成的文件:
Archive the artifacts,配置文件匹配规则

jenkins web页面配置结束

##如果要自定义workspace,在高级项目选项中配置

6.pom.xml配置
如果项目本身是用maven配置的,那配置起来很容易,但如果是用ant做build工作,可以使用maven调用ant进行build

点击(此处)折叠或打开

  1. <plugin>
  2.                 <artifactId>maven-antrun-plugin</artifactId>
  3.                 <version>1.7</version>
  4.                 <executions>
  5.                     <execution>
  6.                         <phase>generate-sources</phase>
  7.                         <configuration>
  8.                             <tasks>
  9.                                 <property name="compile_classpath" refid="maven.compile.classpath" />
  10.                                 <property name="runtime_classpath" refid="maven.runtime.classpath" />
  11.                                 <property name="test_classpath" refid="maven.test.classpath" />
  12.                                 <property name="plugin_classpath" refid="maven.plugin.classpath" />
  13.                                 <property name="artifactId" value="${project.artifactId}" />
  14.                                 <property name="version" value="${project.version}" />
  15.                                 <property name="build.compiler" value="extJavac" />
  16.                                 <ant antfile="build.xml" target="dist" />
  17.                             </tasks>
  18.                         </configuration>
  19.                         <goals>
  20.                             <goal>run</goal>
  21.                         </goals>
  22.                     </execution>
  23.                 </executions>
  24.             </plugin>

build.compiler参数配置很重要,mvn默认使用的是jre,会导致ant无法正常编译

配置源代码路径:

点击(此处)折叠或打开

  1. <sourceDirectory>${basedir}/src</sourceDirectory>
  2.         <outputDirectory>${basedir}/classes</outputDirectory>

配置complile和外部jar包
       

点击(此处)折叠或打开

  1. <plugin>
  2.                 <artifactId>maven-compiler-plugin</artifactId>
  3.                 <version>2.3.2</version>
  4.                 <configuration>
  5.                     <source>1.7</source>
  6.                     <target>1.7</target>
  7.                     <encoding>UTF-8</encoding>
  8.                     <compilerArguments>
  9.                         <extdirs>${basedir}/lib</extdirs>
  10.                     </compilerArguments>
  11.                 </configuration>
  12.             </plugin>

配置checkstyle、pmd:
 

点击(此处)折叠或打开

  1. <pluginManagement>
  2.             <plugins>
  3.                 <plugin>
  4.                     <groupId>org.apache.maven.plugins</groupId>
  5.                     <artifactId>maven-checkstyle-plugin</artifactId>
  6.                     <version>2.17</version>
  7.                     <configuration>
  8.                         <configLocation>sun_checks_eclipse.xml</configLocation>
  9.                     </configuration>
  10.                     <dependencies>
  11.                         <dependency>
  12.                             <groupId>com.puppycrawl.tools</groupId>
  13.                             <artifactId>checkstyle</artifactId>
  14.                             <version>6.17</version>
  15.                         </dependency>
  16.                     </dependencies>
  17.                 </plugin>
  18.                 <plugin>
  19.                     <groupId>org.apache.maven.plugins</groupId>
  20.                     <artifactId>maven-pmd-plugin</artifactId>
  21.                     <version>3.6</version>
  22.                 </plugin>
  23.             </plugins>
  24.         </pluginManagement>


配置findbugs:

点击(此处)折叠或打开

  1. <reporting>
  2.         <plugins>
  3.             <!--FindBugs插件。maven goal:findbugs:findbugs -->
  4.             <plugin>
  5.                 <groupId>org.codehaus.mojo</groupId>
  6.                 <artifactId>findbugs-maven-plugin</artifactId>
  7.                 <version>3.0.3</version>
  8.                 <configuration>
  9.                     <effort>Default</effort>
  10.                     <findbugsXmlOutput>true</findbugsXmlOutput>
  11.                     <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
  12.                     <xmlOutput>true</xmlOutput>
  13.                 </configuration>
  14.             </plugin>
  15.         </plugins>
  16.     </reporting>



7.其他
如果项目之前没有使用checkstyle,再应用checkstyle,会发现大量的警告信息(我发现了几十万条)
这种情况,可以通过eclipse的checkstyle插件自定义符合自己项目的checkstyle配置

附pom.xml:

点击(此处)折叠或打开

  1. <project>
  2.     <modelVersion>4.0.0</modelVersion>
  3.     <artifactId>project-A</artifactId>
  4.     <groupId>project-A-group</groupId>
  5.     <version>1.0</version>
  6.     <build>
  7.         <sourceDirectory>${basedir}/src</sourceDirectory>
  8.         <outputDirectory>${basedir}/classes</outputDirectory>
  9.         <plugins>
  10.             <plugin>
  11.                 <artifactId>maven-antrun-plugin</artifactId>
  12.                 <version>1.7</version>
  13.                 <executions>
  14.                     <execution>
  15.                         <phase>generate-sources</phase>
  16.                         <configuration>
  17.                             <tasks>
  18.                                 <property name="compile_classpath" refid="maven.compile.classpath" />
  19.                                 <property name="runtime_classpath" refid="maven.runtime.classpath" />
  20.                                 <property name="test_classpath" refid="maven.test.classpath" />
  21.                                 <property name="plugin_classpath" refid="maven.plugin.classpath" />
  22.                                 <property name="artifactId" value="${project.artifactId}" />
  23.                                 <property name="version" value="${project.version}" />
  24.                                 <property name="build.compiler" value="extJavac" />
  25.                                 <ant antfile="build.xml" target="dist" />
  26.                             </tasks>
  27.                         </configuration>
  28.                         <goals>
  29.                             <goal>run</goal>
  30.                         </goals>
  31.                     </execution>
  32.                 </executions>
  33.             </plugin>
  34.             <plugin>
  35.                 <artifactId>maven-compiler-plugin</artifactId>
  36.                 <version>2.3.2</version>
  37.                 <configuration>
  38.                     <source>1.7</source>
  39.                     <target>1.7</target>
  40.                     <encoding>UTF-8</encoding>
  41.                     <compilerArguments>
  42.                         <extdirs>${basedir}/lib</extdirs>
  43.                     </compilerArguments>
  44.                 </configuration>
  45.             </plugin>
  46.         </plugins>
  47.         <pluginManagement>
  48.             <plugins>
  49.                 <plugin>
  50.                     <groupId>org.apache.maven.plugins</groupId>
  51.                     <artifactId>maven-checkstyle-plugin</artifactId>
  52.                     <version>2.17</version>
  53.                     <configuration>
  54.                         <configLocation>sun_checks_eclipse.xml</configLocation>
  55.                     </configuration>
  56.                     <dependencies>
  57.                         <dependency>
  58.                             <groupId>com.puppycrawl.tools</groupId>
  59.                             <artifactId>checkstyle</artifactId>
  60.                             <version>6.17</version>
  61.                         </dependency>
  62.                     </dependencies>
  63.                 </plugin>
  64.                 <plugin>
  65.                     <groupId>org.apache.maven.plugins</groupId>
  66.                     <artifactId>maven-pmd-plugin</artifactId>
  67.                     <version>3.6</version>
  68.                 </plugin>
  69.             </plugins>
  70.         </pluginManagement>
  71.     </build>
  72.     <reporting>
  73.         <plugins>
  74.             <!--FindBugs插件。maven goal:findbugs:findbugs -->
  75.             <plugin>
  76.                 <groupId>org.codehaus.mojo</groupId>
  77.                 <artifactId>findbugs-maven-plugin</artifactId>
  78.                 <version>3.0.3</version>
  79.                 <configuration>
  80.                     <effort>Default</effort>
  81.                     <findbugsXmlOutput>true</findbugsXmlOutput>
  82.                     <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
  83.                     <xmlOutput>true</xmlOutput>
  84.                 </configuration>
  85.             </plugin>
  86.         </plugins>
  87.     </reporting>
  88. </project>



阅读(3300) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~