1、下載jdk並安裝(最好jdk官網下載解壓安裝的)java
2、下載maven並安裝mavennode
3、安裝jenkins及插件git
安裝checkstyle、pmd、findbugs、maven、sonar等相關插件github
4、設置全局變量web
5、測試文件下載redis
使用 alibaba 的 fastjson 來演示:
下載: https://github.com/alibaba/fastjson/archive/master.zip spring
配置svn服務並把測試文件的內容放入svn中apache
6、配置jenkinsjson
#測試的svn地址vim
7、配置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>
###配置maven編譯參數
package -Dmaven.test.skip=true findbugs:findbugs checkstyle:checkstyle pmd:pmd
##將findbugs等插件打勾
8、配置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語句必須制定
9、sonar設置
登陸admin帳號 SCM設爲True
10、結果
11、設置郵件發送信息