我正在开发grails 2.3.4应用程序,我正在尝试添加maven(3.1.1)用于构建目的。我是这样做的,因为我的项目是模块化的(2个插件,1个应用程序 - 现在,以后会有更多的插件)我希望有支持它的工具(我没有使用Gradle但这完全是另一个主题)。最近我发现了一些我不理解的问题,这让我的大脑受到了伤害。对于他们的任何帮助,我将非常感激。
我的项目结构如下:
my_project/
my_project-domain/ (plugin)
pom.xml
my_project-services/ (plugin)
pom.xml
my_project-webap/ (app)
pom.xml
pom.xml
我的父pom.xml:
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.app.group</groupId>
<artifactId>myArtifactId</artifactId>
<packaging>pom</packaging>
<version>0.0.2</version>
<name>myArtifactId</name>
<properties>
<grails.version>2.3.4</grails.version>
<h2.version>1.3.170</h2.version>
</properties>
<repositories>
...
</repositories>
<modules>
<module>my_project-domain</module>
<module>my_project-services</module>
<module>my_project-webapp</module>
</modules>
<dependencies>
<!-- MONGODB -->
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>mongodb</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
<type>zip</type>
<exclusions>
<!-- proper spring-core and spring-beans version included by org.grails:grails-plugin-services -->
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- TOMCAT needed during testing -->
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>tomcat</artifactId>
<version>7.0.47</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<!-- without h2 TOMCAT throws DataSource errors -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<!-- GRAILS dependencies-->
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-plugin-async</artifactId>
<version>${grails.version}</version>
</dependency>
...
</dependencies>
<build>
<pluginManagement/>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
...
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<configuration>
<fork>true</fork>
<!-- for debugging <forkDebug>true</forkDebug> -->
</configuration>
<extensions>true</extensions>
...
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>tools</id>
...
</profile>
</profiles>
</project>
示例子pom.xml:
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.app.group</groupId>
<artifactId>myArtifactId</artifactId>
<version>0.0.2</version>
<relativePath>..</relativePath>
</parent>
<groupId>my.app.group</groupId>
<artifactId>my_project-services</artifactId>
<packaging>grails-plugin</packaging>
<version>0.0.2</version>
<name>my_project-services</name>
<description>my_project-services</description>
<dependencies>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>rest</artifactId>
<version>0.8</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
</dependencies>
</project>
我可以通过以下方式执行集成测试:
所以,如果有人试图混合grails 2.3,也许你有一些关于:
的信息如何配置maven以便能够运行mvn grails:来自父pom的test-app,而不是有这样的结果:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] myArtifactId
[INFO] my_project-domain
[INFO] my_project-services
[INFO] my_project-webapp
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myArtifactId 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- grails-maven-plugin:2.3.4:test-app (default-cli) @ myArtifactId ---
|Loading Grails 2.3.4
|Configuring classpath
|Running pre-compiled script
.
|Environment set to test
.......
|Application metadata not found, please run: grails upgrade
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] myArtifactId ..................................... FAILURE [7.116s]
[INFO] my_project-domain ................................ SKIPPED
[INFO] my_project-services .............................. SKIPPED
[INFO] my_project-webapp ................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
为什么mvn grails:test-app
传递和mvn grails:exec -Dcommand=tests-app
执行的集成测试失败以及如何解决?我需要exec命令用于某些特定目的,我希望能够依赖它。这是我最大的问题,我完全不明白它可能是什么原因
mvn grails:tests-app
导致双重测试执行?为什么我需要为tomcat添加h2依赖?在我的dataSources中,我只有mongodb配置,我只想坚持下去,每次执行集成测试时都看不到下面的错误:
|Completed 8 unit tests, 0 failed in 0m 2s
........pool.ConnectionPool Unable to create initial connections of pool.
java.sql.SQLException: org.h2.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
...
Caused by: java.lang.ClassNotFoundException: org.h2.Driver
at org.grails.launcher.RootLoader.findClass(RootLoader.java:147)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at org.grails.launcher.RootLoader.loadClass(RootLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:246)
... 331 more
........
|Running 4 integration tests...
感谢所有到目前为止并仍在阅读的人 - 无论你是否可以提供帮助:)
汤姆