【Maven實戰】之生成專案站點
阿新 • • 發佈:2019-02-02
最簡單的站點
- 通過【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+
- 執行Maven命令
mvn site
專案報告外掛
JavaDoc
- 基於專案原始碼生成JavaDocs文件
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</reporting>
Source Xref
- 將原始碼通過web形式出來,方便團隊之間的交流
<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
- 幫助Java開發人員遵循編碼規範的工具
<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配置
<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
<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
- 需要額外配置拓展外掛【wagon-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