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

Maven 封装 跳过文件,测试

2012-07-19 
Maven 打包 跳过文件,测试??打包时不将资源文件夹下的文件打入包中?pom.xml??buildpluginsplugingr

Maven 打包 跳过文件,测试

?


?

打包时不将资源文件夹下的文件打入包中?

pom.xml

?

?

<build>     <plugins>   <plugin>       <groupId>org.apache.maven.plugins</groupId>       <artifactId>maven-war-plugin</artifactId>       <version>2.0.2</version>       <configuration>        <warSourceExcludes>src/main/resources/**</warSourceExcludes>       </configuration>      </plugin>     </plugins>    </build>
?

跳过测试

1. pom.xml

?

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-surefire-plugin</artifactId>      <configuration>          <skip>true</skip>      </configuration> </plugin>
?

2. 命令

mvn test -Dmaven.test.failure.ignore=true
mvn install -Dmaven.test.skip=true




如果想跳过测试阶段,可用:


mvn package -DskipTests

想临时性跳过测试代码的编译,可用:


mvn package -Dmaven.test.skip=true
maven.test.skip同时控制 maven-compiler-plugin 和 maven-surefire-plugin

两个插件的行为,即跳过编译,又跳过测试。

指定测试类
mvn test -Dtest=RandomGeneratorTest

以Random开头,Test结尾的测试类
mvn test -Dtest=Random*Test

用逗号分隔指定多个测试用例
mvn test -Dtest=ATest,BTest

test参数必须匹配至少一个测试类,否则会报错并导致构建失败。此时可使用以下配置来指定即使没有任何测试用例也不要报错。
mvn test -Dtest -DfailIfNoTests = false


POM文件配置包含与排除测试用例,使用** / * Test.java?来匹配所有以Tests结尾的Java类。两个星号**用来匹配任意路径,一个星号*用来获取除路径风格符外的0个或多个字符。还可使用excludes来排除一些测试类。

<plugin>    <groupId>org.apahce.maven.plugins<groupId>    <artifactId>maven-surefire-plugin</artifactId>    <version>2.5</version>    <configuration>        <includes>            <include>**/*Tests.java</include>        </includes>    </configuration>        </plugin>
?

热点排行