1

I am developing grails 2.3.4 application and I'm trying to add maven (3.1.1) for build purposes. I do it so because my project is modularized (2 plugins, 1 app - for now, there will be many more plugins later) and I would like to have tool that supports it (I failed to use Gradle but thats totally another topic). Recently I found some problems that I don't understand and which makes my brain hurt. I would be very grateful for any help about them.

My project structure looks like this:

my_project/
 my_project-domain/ (plugin)
  pom.xml
 my_project-services/ (plugin)
  pom.xml
 my_project-webap/ (app)
  pom.xml
 pom.xml

My parent 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>

Sample child 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>

I can execute integration tests trough:

  • mvn test - (from parent dir or child dirs) - which executes only unit tests
  • grails:test-app - (from child dir) - which executes unit and integration tests
  • mvn grails:test-app - (only from child dir) which executes unit and integration tests - but it executes them two times instead of one (u,i and then once more u,i)
  • mvn grails:execute -Dcommand=test-app - (only from child dir) - which executes unit and integration tests in the right amount (u,i) BUT during integration tests some of them suddenly start fail(!!!!) It just blows my mind why..

So, if there is anybody who tried to mix grails 2.3, maybe you have some information about:

  1. how can I configure maven to be able to run mvn grails:test-app from parent pom, not to have such result:

    [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] ------------------------------------------------------------------------
    
  2. why integration tests executed by mvn grails:test-app pass and by mvn grails:exec -Dcommand=tests-app fail and how to fix it? I would need exec command for some specific purposes and I want to be able to rely on it. It's my biggest problem, I totally don't understand what could be it's cause

  3. why mvn grails:tests-app results in double tests execution?
  4. why I need to add h2 dependency for tomcat? In my dataSources I have only mongodb configuration and I would like to stick only to it and not see below error every time I execute integration tests:

    |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...
    

Thanks for everybody who got so far and is still reading - no matter if you can help or not:)

Tom

Tom
  • 181
  • 1
  • 8

0 Answers0