我正在使用Grails 2.1.0和Maven 2.1.1。当运行命令mvn clean install
以生成EAR文件时,Maven运行单元测试没有任何问题,除了运行它们两次,然后运行集成测试。当它进入集成测试阶段时,它会抛出错误Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver'
。
单元和集成测试在Grails运行时全部通过,如果我使用-Dmaven.test.skip=true
标记构建耳朵,它会构建没有错误,并且生成的EAR可以很好地部署到服务器。
我正在从1.3.7升级此项目,并且该版本在构建时未运行集成测试。它也只进行过一次单元测试,但是从我读过的两次测试来看,它是grails-maven插件的一个已知部分。下面是我正在使用的pom。
<properties>
<grails.version>2.1.0</grails.version>
<slf4j.version>1.6.6</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-dependencies</artifactId>
<version>${grails.version}</version>
<exclusions>
<exclusion>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</exclusion>
</exclusions>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-plugin-testing</artifactId>
<version>${grails.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>mail</artifactId>
<version>1.0.1</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>jquery</artifactId>
<version>1.7.2</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>resources</artifactId>
<version>1.1.6</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>webxml</artifactId>
<version>1.4.1</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-hibernate</artifactId>
<version>${grails.version}</version>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>hibernate</artifactId>
<version>${grails.version}</version>
<scope>compile</scope>
<type>zip</type>
</dependency>
</dependencies>
<build>
<pluginManagement />
<plugins>
<!-- Disables the Maven surefire plugin for Grails applications, as we have our own test runner -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>plugins</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<configuration>
<!-- Whether for Fork a JVM to run Grails commands -->
<fork>false</fork>
</configuration>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我已尝试删除maven-functional-test
目标以及整个执行部分,但无论如何都会遇到同样的问题。有什么想法吗?
答案 0 :(得分:5)
我尝试使用maven failsafe插件http://maven.apache.org/surefire/maven-failsafe-plugin/examples/skipping-test.html
并添加到我的pom.xml ......
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.10</version>
<configuration>
<skipITs>true</skipITs>
</configuration>
</plugin>
但是mvn clean install仍然运行功能测试。不知道为什么grails如此顽固。
我真的只关心跳过grails-maven功能测试,也许你的情况可以尝试:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
如果有人偶然发现这篇文章,最后找到一个可以跳过grails-maven-functional-test的工作。它需要maven 2.2或更高版本并将其添加到您的pom.xml:
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>default-maven-functional-test</id>
<phase>integration-test</phase>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>