jenkins插件findbugs+pmd+checkstyle结合sonar与maven(java环境代码质量和代码规范管理)
一、下载jdk并安装(最好jdk官网下载解压安装的)
二、下载maven并安装maven
三、安装jenkins及插件
安装checkstyle、pmd、findbugs、maven、sonar等相关插件
四、设置全局变量
五、测试文件下载
使用 alibaba 的 fastjson 来演示:
下载: https://github.com/alibaba/fastjson/archive/master.zip
配置svn服务并把测试文件的内容放入svn中
六、配置jenkins
#测试的svn地址
七、配置pom.xml文件
在pom.xml文件中添加以下内容
vim pom.xml
<project ...>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> <!-- ...... --> <reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<linkXRef>false</linkXRef>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<configuration>
<linkXref>false</linkXref>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
修改后的文件
<?xml version="1.0" encoding="UTF-8"?>
<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>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.50-SNAPSHOT</version> <packaging>jar</packaging>
<name>fastjson</name>
<description>Fastjson is a JSON processor (JSON parser + JSON generator) written in Java</description> <url>https://github.com/alibaba/fastjson</url>
<inceptionYear>2012</inceptionYear> <properties>
<junit.version>4.12</junit.version>
<gpg.skip>true</gpg.skip>
<javadoc.skip>false</javadoc.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.5</jdk.version>
</properties> <scm>
<url>https://github.com/alibaba/fastjson</url>
<connection>scm:git:https://git@github.com/alibaba/fastjson.git</connection>
</scm> <repositories>
<repository>
<id>local-file</id>
<url>file://${basedir}/lib/</url>
<layout>default</layout>
</repository>
</repositories> <organization>
<name>Alibaba Group</name>
<url>https://github.com/alibaba</url>
</organization> <developers>
<developer>
<id>wenshao</id>
<name>wenshao</name>
<email>szujobs@hotmail.com</email>
</developer>
<developer>
<id>axmanwang</id>
<name>axmanwang</name>
<email>iamaxman@hotmail.com</email>
</developer>
<developer>
<id>kimmking</id>
<name>kimmking</name>
<email>kimmking@163.com</email>
</developer>
<developer>
<id>Victor Zeng</id>
<name>Victor Zeng</name>
<email>Victor.Zxy@outlook.com</email>
</developer>
<developer>
<id>Neil Dong</id>
<name>Neil Dong</name>
<email>email_dsl@163.com</email>
</developer>
<developer>
<name>李恒名</name>
<url>https://github.com/lihengming/</url>
<email>89921218@qq.com</email>
</developer>
</developers> <licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses> <build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
<configuration>
<attach>true</attach>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/bvt/**/*.java</include>
</includes>
</configuration>
</plugin> <plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>${javadoc.skip}</skip>
<show>public</show>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<links>
<link>http://docs.oracle.com/javase/6/docs/api</link>
</links>
</configuration>
</plugin> <plugin>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<skip>${gpg.skip}</skip>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build> <dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>4.3.7.RELEASE</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.3.7.RELEASE</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> <dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.6.RELEASE</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> <dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<version>2.6.1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> <dependency>
<groupId>io.javaslang</groupId>
<artifactId>javaslang</artifactId>
<version>2.0.6</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.23.2</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.8.v20121106</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.8.v20121106</version>
<scope>test</scope>
<optional>true</optional>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2.2</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.2.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.1.5</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.7.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.0-GA</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.1.2</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>1.4.1.RELEASE</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.23.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.23.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jdk-http</artifactId>
<version>2.23.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jsoniter</groupId>
<artifactId>jsoniter</artifactId>
<version>0.9.8</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.1.3-2</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>1.1.3-2</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.3.RELEASE</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.diffblue</groupId>
<artifactId>deeptestutils</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.4</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.21</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.21</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.3.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
<exclusion>
<artifactId>jackson</artifactId>
<groupId>jackson-mapper-asl</groupId>
</exclusion>
<exclusion>
<artifactId>jackson</artifactId>
<groupId>jackson-core-asl</groupId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency> </dependencies> <profiles>
<profile>
<id>travis</id>
<activation>
<property>
<name>env.TRAVIS</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<!-- for codecov.io -->
<!-- config example: https://github.com/codecov/example-java -->
<!-- plugin docs: http://eclemma.org/jacoco/trunk/doc/ -->
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile> </profiles>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<linkXRef>false</linkXRef>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<configuration>
<linkXref>false</linkXref>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
pom.xml
###配置maven编译参数
package -Dmaven.test.skip=true findbugs:findbugs checkstyle:checkstyle pmd:pmd
##将findbugs等插件打勾
八、配置sonar参数
参数
sonar.host.url=http://localhost:9000 #建议公网ip
sonar.sourceEncoding=UTF-8 ##字符集
sonar.projectKey=test-key #自定义的key
sonar.projectName=test ##自定义名称
sonar.projectVersion=1.0 ##自定义版本
sonar.sources=/mnt/fastjson-master ##代码目录
sonar.java.binaries=/mnt/fastjson-master ##java语句必须制定
九、sonar设置
登录admin账号 SCM设为True
十、结果
十一、设置邮件发送信息
jenkins插件findbugs+pmd+checkstyle结合sonar与maven(java环境代码质量和代码规范管理)的更多相关文章
- Jenkins 配置 FindBugs,Checkstyle,PMD 实现代码的静态检查 (14)
一.插件介绍 FindBugs:静态分析工具,它检查类或者 JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题.利用这个工具,就可以在不实际运行程序的情况对软件进行分析.它可以帮助改进代码的 ...
- 使用Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(一)
前言 但凡一个略有规模的项目都需要一个持续集成环境的支撑,为什么需要持续集成环境,我们来看一个例子.假如一个项目,由A.B两位程序员来协作开发,A负责前端模块,B负责后端模块,前端依赖后端.A ...
- 使用Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境
前言 但凡一个略有规模的项目都需要一个持续集成环境的支撑,为什么需要持续集成环境,我们来看一个例子.假如一个项目,由A.B两位程序员来协作开发,A负责前端模块,B负责后端模块,前端依赖后端.A和B都习 ...
- Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境
使用Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(一) 2015-01-14 20:28 by 飘扬的红领巾, 4322 阅读, 5 评论, 收藏, 编辑 ...
- Jenkins与Git持续集成&&Linux上远程部署Java项目
一.环境搭建 1.安装所需软件 Jdk Maven Jenkins Tomcat Xshell git 以上软件去官网下载,比较简单,不一一描述了 2.安装所需的jenkins插件 Git plugi ...
- Docker+Jenkins持续集成环境(3)集成PMD、FindBugs、Checkstyle静态代码检查工具并邮件发送检查结果
为了规范代码,我们一般会集成静态代码检测工具,比如PMD.FindBugs.Checkstyle,那么Jenkins如何集成这些检查工具,并把检查结果放到构建邮件里呢? 今天做了调研和实现,过程如下 ...
- eclipse插件之Findbugs、Checkstyle、PMD安装及使用
eclipse插件之Findbugs.Checkstyle.PMD安装及使用 一.什么是Findbugs.checkstyle.PMD Findbugs.checkstyle和PMD都可以作为插件插入 ...
- idea配置checkstyle/findbugs/pmd插件
前提条件:工程已导入idea 一,Findbugs/PMD/CheckStyles插件安装 打开settings的plugins,点击查找FindBugs-IDEA/PMDPlugin/CheckSt ...
- 提高代码质量 CheckStyle FindBugs PMD
提高代码质量-工具篇 注:这是一篇翻译文章,原文:How to improve quality and syntax of your Android code,为了理解连贯,翻译过程中我修改了一些陈述 ...
随机推荐
- [TJOI2017]DNA
嘟嘟嘟 这题怎么想都想不出来,最后还是敲了暴力,喜提40分-- 正解竟然也是暴力-- 用\(s_0\)构造SAM,然后把\(s\)扔上去暴力dfs:记录一个修改次数tot,如果当前不匹配,就tot + ...
- LINUX 查看当前系统的内存使用情况 free
每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code # free 显示结果如下: Mem:表示物理内存统计 total 内存总数 8057 ...
- automake - 使用 autotools 工具集
一般而言,对于小项目或玩具程序,手动编写 Makefile 即可.但对于大型项目,手动编写维护 Makefile 成为一件费时费力的无聊工作. 本文介绍 autotools 工具集自动生成符合 Lin ...
- shut immediate 数据库遭遇 ORA-24324 ORA-24323
SQL> shut immediateORA-24324: service handle not initializedORA-24323: value not allowedORA-27140 ...
- 数组升序排序的方法Arrays.sort();的应用
package com.Summer_0421.cn; import java.util.Arrays; /** * @author Summer * 数组升序排序的方法Arrays.sort();应 ...
- # 20175329 2018-2019-2 《Java程序设计》第一周学习总结
教材学习内容总结 ·通过教材学习了如何安装JAVA ·在安装JAVA后对其环境变量的设置 ·第一次接触并手打出JAVA语言## 教材学习中的问题和解决过程- 问题1:在环境变量设置中不懂path cl ...
- AutoMapper快速上手
一.什么是AutoMapper AutoMapper是一个简单的对象映射框架(OOM),对象映射原理是把一种类型的输入对象转换为不同类型的输出对象,通俗讲就是通过一些约束讲一种类型中数据自动映射到另 ...
- RabbitMQ详解(二)------消息通信的概念
PS:近期在南宁出差,工作比较忙,所以更新会比较慢. 说到消息通信,可能我们首先会想到的是邮箱,QQ,微信,短信等等这些通信方式,这些通信方式都有发送者,接收者,还有一个中间存储离线消息的容器.但是这 ...
- Jlink使用技巧之读取STM32内部的程序
前言 上一篇Jlink系列文章介绍了如何使用J-Flash来下载Hex或Bin文件到单片机,具体可参考Jlink使用技巧之单独下载HEX文件到单片机,本篇文章介绍,如何使用JFlash来读取单片机的程 ...
- JasperReport子报表参数传递
子报表参数传递 下图的参数名称可以自定义 再子报表新增一个同名称的参数即可