首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

第七章 生命周期跟插件

2012-07-15 
第七章生命周期和插件?http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

第七章 生命周期和插件

?

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings

查看具体的绑定关系。由于项目的打包类型会影响构建的具体过程,因此default生命周期的阶段与插件目标的绑定关系由项目打包类型决定。

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1.1</version> <executions> <execution> <id>attach-sources</id> <phase>verify</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> </plugins></build> ?

可以将mven-source-plugin中的jar-no-fork目标(将项目的主代码打包成jar文件)绑定到verify这个phase。

?

Mvn help:describe –Dplugin=org.apache.maven.plugins:maven-source-plugin:2.1.1–Ddetail。

?

默认绑定与自定义绑定的执行顺序是?

?

Mvn install –Dmaven.test.skip=true

maven.test.skip是maven-surefire-plugin的一个参数,当其值为true时,就会跳过执行测试。

?

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.1</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin></plugins></build> ?

该配置告诉maven-compiler-plugin要编译的源文件是Java 1.5的,并且生成与JVM1.5兼容的字节代码文件。由于maven-compiler-plugin被绑定到compile与test-compile阶段,所以上述配置对这两个阶段都会生效。

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> <executions> <execution> <id>ant-validate</id> <phase>validate</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>I’m bound to validate phase.</echo> </tasks> </configuration> </execution> <execution> <id>ant-verify</id> <phase>verify</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>I’m bound to verify phase.</echo> </tasks> </configuration> </execution> </executions></plugin> ?

以上配置将maven-antrun-plugin:run绑定到了validate与verify两个phase,但为两个phase设置了不同的参数。

插件来源

插件列表

下载地址

Apache

http://maven.apache.org/plugins/index.html

http://repo1.maven.org/maven2/org/apache/maven/plugins

Codehaus

http://mojo.codehaus.org/plugins.html

http://repository.codehaus.org/org/code-haus/mojo/

?

Maven-surefire-plugin的skip参数,Expression为:${maven.test.skip}则在命令行中配置该参数时参数名就为-Dmaven.test.skip。而在POM中配置时,参数名为skip。

Mvn help:describe–Dplugin=compiler –Dgoal=compile -Ddetail

<pluginRepositories> <pluginRepository> <id>central</id> <name>Maven Plugin Repository</name> <url>http://repo1.maven.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshosts> <releases> <updatePolicy>never</updatePolicy> </releases> </pluginRepository></pluginRepositories>?

<settings> <pluginGroups> <pluginGroup>com.your.plugins</pluginGroup> </pluginGroups></settings> ?

元数据信息如下:

?

<metadata>  <plugins>    <plugin>      <name>Maven Clean Plugin</name>      <prefix>clean</prefix>       <artifactId>maven-clean-plugin</artifactId>    </plugin>    …  </plugins></metadata> 

热点排行