最简单的站点
- 通过【maven-site-plugin】生成
- Pom配置
Maven3:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
</plugins>
</pluginManagement>
注意:如果报缺少
java.lang.NoClassDefFoundError: org/sonatype/aether/graph/DependencyFilter
则把maven-site-plugin从3.0升级到3.3+
mvn site
项目报告插件
JavaDoc
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</reporting>
Source Xref
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</reporting>
- 如果想在聚合模块整合所有的源码,则需添加格外的aggregate配置
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</reporting>
CheckStyle
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.5</version>
<configuration>
<configLocation>config/maven_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
- 有以下四种编码规则
- config/sun_checks.xml sun定义的编码规范(默认值)
- config/sun_checks.xml Maven社区定义的编码规范
- config/turbine_checks.xml Turbine定义的编码规范
4. config/avalon_checks.xml Avalon定义的编码规范
PMD
- 一款强大的Java源代码分析工具,能够寻找代码中的问题,包括潜在的Bug,无用代码,可优化代码,重复代码以及过于复杂的表达式。
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</reporting>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
</plugins>
</reporting>
ChangeLog
- 基于版本控制系统中就近的变更记录生成三份变更报告,分别是:
- Change Log 基于提交的变更报告,包括每次提交的日期,文件,作者,注释等信息
- Developer Activity 基于作者的变更报告
1. File Activity 基于文件的变更报告
<scm>
<connection>scm:svn:http://192.168.1.103/app/trunk</connection> --表示只读的scm地址
<developerConnection>scm:svn:https://192.168.1.103/app/trunk</developerConnection>--表示一个可写的scm地址
<url>http://192.168.1.103/account/trunk</url>--表示可在浏览器访问的url地址
</scm>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.2</version>
<configuration>
<type>range</type>
<range>60</range>
</configuration>
</plugin>
</plugins>
</reporting>
Cobertura
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</reporting>
部署站点
DAV
<project>
...
<distributionManagement>
<site>
<id>app-site</id>
<url>dav:https://www.baidu.com/sites/app</url>
</site>
</distributionManagement>
...
</project>
- 如果需要认证,则在【setting.xml】配置server
<servers>
<server>
<id>app-site</id>
<username>demo</username>
<password>demo</password>
</server>
</servers>
FTP
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
</build>
<distributionManagement>
<site>
<id>app-site</id>
<url>ftp:https://www.baidu.com/sites/app</url>
</site>
</distributionManagement>
...
</project>
SCP
<project>
...
<distributionManagement>
...
<site>
<id>app-site</id>
<url>scp:https://www.baidu.com/sites/app</url>
</site>
</distributionManagement>
...
</project>
- 注意:与dav和ftp不同的是,scp协议通常使用密钥进行认证,因此在【setting.xml】配置认证信息时,有可能需要【passphrase】和【privateKey】,如下
<servers>
<server>
<id>app-site</id>
<passphrase>demo</passphrase>
<privateKey>demo</privateKey>
</server>
</servers>
- 布置完后,只需要输入以下命令就能够让Maven部署站点:
mvn clean site-deploy