我使用的是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,它就会正确地构建,并且生成的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目标,以及整个executions部分,但都遇到了同样的问题。有什么想法吗?
发布于 2014-03-27 23:52:40
我试着使用maven的故障安全插件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全新安装仍然运行功能测试。不知道为什么圣杯如此固执。
我真的只关心跳过grails-maven-functional测试,也许你可以尝试一下:
<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>https://stackoverflow.com/questions/22665341
复制相似问题