<project> ... ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> </plugin> </plugins> </build> ... ... </project>2.配置正确版本之后,在项目之下运行mvn site就能直接生成一个最简单的站点;
C:\Users\chengxiang.peng.QUNARSERVERS\QunarGitSources\phone_spider_project>mvn site [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building check phone 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-site-plugin:3.3:site (default-site) @ phoneproject --- [WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version. [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:2.9 [WARNING] No project URL defined - decoration links will not be relativized! [INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.0 skin. [INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Dependency Convergence" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Dependency Information" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "About" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Plugins" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Summary" report --- maven-project-info-reports-plugin:2.9 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 29.989 s [INFO] Finished at: 2016-10-20T12:09:41+08:00 [INFO] Final Memory: 26M/357M [INFO] ------------------------------------------------------------------------3.待Maven运行完成后,可以再项目的target/site/目录下找到Maven生成的站点文件,包括dependencies.html、dependency-convergence.html、index.html和css、images文件夹;
<project> ... ... <url>http://phoneproject.qunar.com</url> <!--项目描述信息--> <description>check phone description.</description> <!--源码仓库信息--> <scm> <connection>scm:git:http://gitlab.corp.chengxiang.com/mobile_hotel_res/phone_spider_project</connection> <developerConnection>scm:git:[email protected]:mobile_hotel_res/phone_spider_project.git </developerConnection> <url>http://gitlab.corp.chengxiang.com/mobile_hotel_res/phone_spider_project</url> </scm> <!--持续化集成服务信息--> <ciManagement> <system>Jenkins</system> <url>http://ci.chengxiang.com/phoneproject</url> </ciManagement> <!--项目成员信息--> <developers> <developer> <id>chengxiang.peng</id> <name>chengxiang.peng</name> <email>[email protected]</email> <timezone>8</timezone> </developer> </developers> <!--问题跟踪信息--> <issueManagement> <system>JIRA</system> <url>http://jira.chengxiang.com/phoneproject</url> </issueManagement> ... ... </project>3.执行mvn site重新生成站点,发现对比简单站点,多生成了如 "CI Management" report、"Source Code Management" report等;
C:\Users\chengxiang.peng.QUNARSERVERS\QunarGitSources\phone_spider_project>mvn site [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building check phone 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-site-plugin:3.3:site (default-site) @ phoneproject --- [WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version. [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:2.9 [INFO] Relativizing decoration links with respect to project URL: http://phoneproject.qunar.com [INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.0 skin. //新增的报告生成 [INFO] Generating "CI Management" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Dependency Convergence" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Dependency Information" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "About" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Issue Management" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Plugins" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Team" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Source Code Management" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Summary" report --- maven-project-info-reports-plugin:2.9 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 19.624 s [INFO] Finished at: 2016-10-20T15:21:46+08:00 [INFO] Final Memory: 26M/354M [INFO] ------------------------------------------------------------------------
3.有些时候,我们并不需要生成某些项目信息,如可能不想公开源码仓库信息。可以通过maven-project-info-reports-plugin选择性生成信息项目,pom.xml配置如下:
<project> ... ... <!--报告配置--> <reporting> <plugins> <!--maven-project-info-reports-plugin报告插件集成在site中,故不同配置build/plugins/plugin。配置生成什么报告, 如下配置只生成dependencies、project-team和mailing-list--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.9</version> <reportSets> <reportSet> <reports> <report>dependencies</report> <report>project-team</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting> ... ... </project>4.mvn site生成站点:
C:\Users\chengxiang.peng.QUNARSERVERS\QunarGitSources\phone_spider_project>mvn site [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building check phone 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-site-plugin:3.3:site (default-site) @ phoneproject --- [INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:2.9 [INFO] Relativizing decoration links with respect to project URL: http://phoneproject.qunar.com [INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.0 skin. //只生成了上面配置的Dependencies和Team报告 [INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:2.9 [INFO] Generating "Team" report --- maven-project-info-reports-plugin:2.9 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 36.054 s [INFO] Finished at: 2016-10-20T15:30:33+08:00 [INFO] Final Memory: 24M/275M [INFO] ------------------------------------------------------------------------三、项目报告插件
<project> ... ... <!--报告配置--> <reporting> <plugins> <!--生成Javadoc文档--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> </plugin> </plugins> </reporting> ... ... </project>
执行mvn site生成站点中,包含javadoc文档Project Reports->JavaDocs如下:
2.Source Xref:能够随时随地打开浏览器访问项目的最新源代码;
pom.xml配置:
<project> ... ... <!--构建配置--> <build> <plugins> <!--引用插件配置--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </build> <!--报告配置--> <reporting> <plugins> <!--报告生成配置--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </reporting> ... ... </project>
执行mvn site生成站点中,包含源码文档Project Reports->Source Xref如下:
<project> ... ... <!--构建配置--> <build> <plugins> <!--代码规范检测插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.5</version> <!--在插件的目标mvn site:site中有效,配置checkstyle检测规则--> <configuration> <configLocation>${project.basedir}/config/checkstyle/checkstyle.xml</configLocation> </configuration> </plugin> </plugins> </build> <!--报告配置--> <reporting> <plugins> <!--代码规范检测报告--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.5</version> <!--在mvn site生命周期有效,配置checkstyle检测规则--> <configuration> <configLocation>${project.basedir}/config/checkstyle/checkstyle.xml</configLocation> </configuration> </plugin> </plugins> </reporting> ... ... </project>Checkstyle.xml配置如下(详细配置信息,查看官方文档:http://checkstyle.sourceforge.net/checks.html):
<?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> <module name="Checker"> <module name="TreeWalker"> <!--包名检测--> <module name="PackageName"> <property name="format" value="^[a-z]+(\.[a-z0-9]*)*$"/> </module> <!--类名检测--> <module name="TypeName"> <property name="format" value="^[A-Z][a-zA-Z0-9]*$"/> <property name="tokens" value="CLASS_DEF"/> </module> … …. <!--成员变量检查--> <module name="LocalVariableName"> <property name="format" value="^[a-z][a-zA-Z_0-9]*$"/> <!--该属性在IEAD中不包裹,在mvn site报错,mvn site -X可以查看详细信息--> <property name="allowOneCharVarInForLoop" value="false"/> </module> </module> … ….. </module>
执行mvn site生成站点中,包含源码文档Project Reports->CheckStyle如下:
<project> ... ... <!--构建配置--> <build> <plugins> <!--代码问题分析插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.7</version> </plugin> </plugins> </build> <!--报告配置--> <reporting> <plugins> <!--代码问题分析报告--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.7</version> </plugin> </plugins> </reporting> ... ... </project>执行mvn site生成站点中,包含源码文档Project Reports->PMD如下:
<project> ... ... <!--构建配置--> <build> <plugins> <!--代码覆盖率检测插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.7</version> </plugin> </plugins> </build> <!--报告配置--> <reporting> <plugins> <!--代码覆盖检测报告--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.7</version> </plugin> </plugins> </reporting> ... ... </project>执行mvn site生成站点中,包含源码文档Project Reports->Coberatura Test如下:
<?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"> <!--1.左边栏--> <bannerLeft> <name>Phone Site</name> <!--访问url图片--> <src>http://tika.apache.org/asf-logo.gif</src> <href>http://www.baidu.com</href> </bannerLeft> <!--2.右边栏--> <bannerRight> <name>java</name> <!--访问本地图片,注意图片路径/site/resources/images/right.jpg--> <src>images/right.jpg</src> <href>http://www.hao123.com</href> </bannerRight> <!--3.显示发布时间位置--> <publishDate position="right"/> <body> <!--4.导航栏链接--> <breadcrumbs> <item name="youku" href="www.youku.com"/> <item name="iqiyi" href="www.iqiyi.com"/> </breadcrumbs> <!--5.导航边栏--> <menu name="${project.name}"> <!--href-引用自定义页面,apttest.apt文件生成--> <item name="apttest" href="apttest.html"/> </menu> <menu name="Examples"> <!--href-引用自定义页面,faqtest.faq文件生成--> <item name="faltest" href="faqtest.html"/> </menu> <!--6.ref-引用默认自动生成的报告页面--> <menu ref="reports"/> </body> <!--7.站点皮肤:如下图与如上有区别--> <skin> <groupId>com.googlecode.fluido-skin</groupId> <artifactId>fluido-skin</artifactId> <version>1.3</version> </skin> </project>src/site/fml/faqtest.fml文件(一种用来创建FAQ页面的XML文档格式)
<?xml version="1.0" encoding="UTF-8"?> <faqs 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 http://maven.apache.org/xsd/fml-1.0.1.xsd" title="fqltest title" toplink="false"> <part id="install"> <title>title1</title> <faq id="download"> <question>what?</question> <answer> <p>answer1</p> <p>answer2</p> </answer> </faq> </part> </faqs>src/site/apt/apttest.apt文件(一种类似于维基的文档格式,用它来快速创建简单而又结构丰富的文档)
what is apt? * aaaa * bbbb3.执行mvn site生成站点中,生成自定义站点如下:
<project> ... ... <!--属性,在POM的其它地方使用${属性名称}的方式引用属性--> <properties> <!--国际化,告诉maven-site-plugin使用UTF-8编码读取所有源码及文档--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <!--构建配置--> <build> <plugins> <!--生成站点插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> <!--国际化定义当地语言--> <configuration> <locales>zh_CN</locales> </configuration> </plugin> </plugins> </build> ... .... </project>3.执行mvn site生成站点中,生成本地化站点如下: