Jade Dungeon

Nexus为本项目生成网站

Nexus为本项目生成网站

生成简单站点

<pluginManagement>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-site-plugin</artifactId>
			<version>3.0-beta-1</version>
		</plugin>
	</plugins>
</pluginManagement>

执行:

mvn site

加入更多的信息

<project>
	...
	<scm><!-- 版本控制 -->
		<connection>scm:svn:http://svn.juvenxu.com/mvnbook/trunk</connection>
		<developerConnection>scm:svn:http://svn.juvenxu.com/mvnbook/trunk</developerConnection>
	</scm>

	<cyManagement><!-- 持续集成系统 -->
		<system>Hudson</system>
		<url>http://ci.juvenxu.com/mvnbook</url>
	</cyManagement>

	<developers><!-- 开发者 -->
		<developer>
			<id>juven</id>
			<name>Juven Xu</name>
			<email>juasd@asdf.com</email>
			<timezo>8</timezo>
		</developer>
	</developers>

	<issueManagement>
		<system>JIRA</system>
		<url>http://jaira.juvenxu.com</url>
	</issueManagement>

	<licenses><!-- 许可证 -->
		<license>Apache License, Version 2.0</license>
		<url>http://www.apache.org/licenses/LICENSE-2.0</url>
	</licenses>

	<report>
		<plugins>
			<plugin>
				<reportSets>
					<reports>
						<report>dependencies</report>
						<report>projet-team</report>
						<report>issue-tracking</report>
						<report>license</report>
					</reports>
				</reportSets>
			</plugin>
		</plugins>
	</report>
	...
</project>

介绍更多插件

JavaDocs

<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>

如果是聚合项目

<reporting>
	<plugins>
		...
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-jxr-plugin</artifactId>
			<version>2.2</version>
			<configuration>
				<aggregate>grue</aggregate>
			</configuration>
		</plugin>
		...
	</plugins>
</reporting>

checkstyle检查代码规范

内置了四种,也可以自己定义,默认使用Sun规范:

  • config/sun_chexks.xml
  • config/maven_chexks.xml
  • config/Turbine_chexks.xml
  • config/Avalon_chexks.xml
<reporting>
	<plugins>
		...
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-checkstyle-plugin</artifactId>
			<version>2.5</version>
			<configuration>
				<confiLocation>config/maven_checks.xml</confiLocation>
			</configuration>
		</plugin>
		...
	</plugins>
</reporting>

自定义代码规范,也是按classpath来找的,所以只要:

  • 放在src/main/resources/checkstyle/my-checks.xml
  • 配置为:<confiLocation>config/my-checks.xml</confiLocation>

如果是聚合工程,插件支持不好,要额外配置。原理就是先定义一个规则, 再加到classpath,再从classpath载入规则。例子:

为check建立一个工程:

  • checkstyle/pom.cml
  • checkstyle/src/main/resources/checkstyle/my-checks.xml

在聚合模块配置maven-checkstyle-plugin依赖该模块:

<build>
	...
	<plugins>
		...
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-checkstyle-plugin</artifactId>
			<version>2.5</version>
			<dependencies>
				<dependency>
					<groupId>com.juvenxu.mvnbook</groupId>
					<artifactId>checkstyle</artifactId>
					<version>1.0</version>
				</dependency>
			</dependencies>
		</plugin>
		...
	</plugins>
	...
</build>

在聚合模块配置maven-checkstyle-plugin使用checkstyle:

<reporting>
	<plugins>
		...
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-checkstyle-plugin</artifactId>
			<version>2.5</version>
			<configuration>
				<confiLocation>config/maven_checks.xml</confiLocation>
			</configuration>
		</plugin>
		...
	</plugins>
</reporting>

PMD分析代码中的问题

aggreate表示聚合项目,ruleset表示规则,规则详见: http://pmd.sourceforge.net/rules/index.html

<reporting>
	...
	<plugins>
		...
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-pmd-plugin</artifactId>
			<version>2.5</version>
			<configuration>
				<rulesets>
					<ruleset>rulesets/braces.xml</ruleset>
					<ruleset>rulesets/naming.xml</ruleset>
					<ruleset>rulesets/strings.xml</ruleset>
				</rulesets>
				<aggregate>true</aggregate>
			</configuration>
		</plugin>
		...
	</plugins>
	...
</reporting>

默认使用规则:

  • rulesets/basic.xml
  • rulesets/unusedcode.xml
  • rulesets/importss.xml


ChangeLog生成修改记录

组合scm定义,默认生成30天的记录,可以手动修改日期跨度:

<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.codehaus.mojo</groupId>
			<artifactId>cobertura-maven-plugin</artifactId>
			<version>2.4</version>
		</plugin>
		...
	</plugins>
	...
</reporting>

站点外观

描述文件

src/site/site.xml,xsd为http://maven.apache.org/xsd/decoration-1.0.0.xsd

<?xml version="1.0" encoding="UTF-8"?>
<project>

	<bannerLeft>
		<name>Account</name>
		<source>../images/apache-maven-project.png</source>
		<href>http://maven.apache.org</href>
	</bannerLeft>

	<body>
		<menu ref="reports"></menu>
	</body>

	<skin>
		<groupId>com.googlecode.fluido-skin</groupId>
		<artifactId>fludio-skin</artifactId>
		<version>1.3</version>
	</skin>

</project>

结构

- src/
	+ site/
		+ recesources/
		|	+ ../images/
		|		+ logo.jpg
		+ site.xml

定义BannerRight:

<project>
	...
	<bannerRight>
		<name>Java</name>
		<source>../images/java</source>
		<href>http://maven.java.com</href>
	</bannerRight>
	...
</project>

发布时间和版本,位置可用:none left right navigation-top navigation-bottom bottoM。例:

<project>
	...
	<version position="right" />
	<publishDates position="right"/>
	...
</project>

导航面包屑:

<project>
	...
	<body>
		<breadecrumbs>
			<item name="aa" href="http://aa.com" />
			<item name="bb" href="http://bb.com" />
		</breadecrumbs>
	</body>
	...
</project>

皮肤

maven官方三款皮肤:

  • org.apache.maven.skins:maven-classic-skin
  • org.apache.maven.skins:maven-default-skin
  • org.apache.maven.skins:maven-stylus-skin

推荐google code上的fluido-skin: 

<project>
	...
	<skin>
		<groupId>com.googlecode.fluido-skin</groupId>
		<artifactId>fluido-skin</artifactId>
		<version>1.3</version>
	</skin>
	...
</project>

自定义导航边栏

可以引用默认生成的<menu ref="reports" />,然后再加上自己定义的菜单内容:

<project>
	...
	<body>
		<menu name="${project.name}">
			<item name="aa1" href="aa1.html"/>
			<item name="aa2" href="aa2.html"/>
			<item name="aa3" href="aa3.html"/>
		</menu>
		<menu name="Examples">
			<item name="Example1" href="example1.html"/>
			<item name="Example2" href="example2.html"/>
			<item name="Example3" href="example3.html"/>
		</menu>
		<menu ref="reports" />
	</body>
	...
</project>

自定义页面

maven支持得比较好的格式有APT和FML。 

APT(Almost Plain Test),类似Wiki格式:

	-------------
	Introduction
	-------------
	Juven Xu
	-------------
	2010-07-20
	-------------

What is Maven?

	Apache Maven is a software

Core Maven Concepts

* Coordiatan
* Coordiatan
* Coordiatan
* Coordiatan

FML(FAQ Markup Language)是用来创建FAQ(Frequently Asked Questions)的:

<?xml version="1.0" encoding="UTF-8"?>
<faqs>

	<part id="install">
		<title>install</title>
		<faq id="download">
			<question>where to download?</question>
			<answer>
				<p>aaa: http://aaa.com</p>
				<p>bbb: http://bbb.com</p>
			</answer>
		</faq>
		<faq id="do-install">
			<question>how to install?</question>
			<answer>
				<p>Description on the install step...</p>
			</answer>
		</faq>
	</part>

	<part id="run">
		<title>run</title>
		<faq id="how-run">
			<question>how to run</question>
			<answer>
				<p>Desc how run ....</p>
			</answer>
		</faq>
	</part>

</faqs>

I18N

编码:

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.report.sourceEncoding>UTF-8</project.report.sourceEncoding>
</properties>

maven-site-plugin的当地语言:

<plugins>
	...
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-site-plugin</artifactId>
		<version>2.1.1</version>
		<configuration>
			<locales>zh_CN</locales>
		</configuration>
	</plugin>
	...
</plugins>

部署站点

mvn clean site-deploy
}}

支持:FTP、SCP、DAV

=== DAV ===

{{{class="brush: xml"
<project>
	...
	<distributionManagement>
		<site>
			<id>app-site</id>
			<url>dav:https://www.aaa.com/sites/app</url>
		</site>
	</distributionManagement>
	...
</project>

如果要认证,一般放在settings.xml的server里:

<settings>
	...
	<servers>
		<server>
			<id>app-site</id>
			<username>jvadw</username>
			<password>******</password>
		</server>
	</servers>
	...
</settings>

FTP

如果是用FTP,还要加上wagon-ftp扩展:

<project>
	...
	<build>
		<plugins>
			...
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-site-plugin</artifactId>
				<version>2.1.1</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://www.aaa.com/sites/app</url>
		</site>
	</distributionManagement>
	...
</project>

SCP

比较简单:

</project>
	...
	<distributionManagement>
		<site>
			<id>app-site</id>
			<url>scp://www.aaa.com/sites/app</url>
		</site>
	</distributionManagement>
	...
</project>

如果要密钥认证,一般放在settings.xml的server里:

<settings>
	...
	<servers>
		<server>
			<id>app-site</id>
			<passphrase>someone</passphrase>
			<privatekey>/home/aa/.ssh/id_rsa</privatekey>
		</server>
	</servers>
	...
</settings>