3

I'm using Maven 3.0.3.
Is it possible to include a dependency for my test phase only, and then another dependency for my integration-phase only? When these two dependencies are included together

<dependency> 
    <groupId>com.google.gwt</groupId> 
    <artifactId>gwt-dev</artifactId> 
    <version>${gwtVersion}</version> 
    <scope>test</scope> 
</dependency> 
... 
<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.13.0</version> 
    <scope>test</scope> 
</dependency> 

I get a java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init> error when running my Selenium integration tests. When the GWT dependency is excluded, the Selenium tests run. I still need the GWT dependency for the test phase, tho.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Dave
  • 15,639
  • 133
  • 442
  • 830
  • How about creating two different profiles? [http://stackoverflow.com/questions/166895/different-dependencies-for-different-build-profiles-in-maven](http://stackoverflow.com/questions/166895/different-dependencies-for-different-build-profiles-in-maven) – matsev Nov 22 '11 at 19:54
  • Have you tried running "mvn dependency:tree" and see what happens with your dependencies in both cases? Maybe you are getting wrong version of Apache HttpClient for some reason? – Ivan Dubrov Nov 22 '11 at 23:39

4 Answers4

2

Use profiles. A profile allows you to add dependencies depending on the arguments of the -P command line option.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Could you provide an example showing how to activate one profile during the test phase and another during the integration-test phase? Also, anyway to make it so that I don't have to explicitly specify the profiles on the command line (e.g. -P testProfile,integrationTestProfile)? The first question is more important -- the second is just a "nice to have." – Dave Nov 28 '11 at 15:50
  • Use `mvn help:effective-pom` to see what you'd get with various `-P` options. To automatically enable/disable profiles, I suggest to use the `` element which activates a profile when a file exists or when it's missing. See the docs. That allows you to run the ITs on your build server and skip them on your development PC unless you specifically request them. Also writing a couple of batch scripts can help. – Aaron Digulla Nov 28 '11 at 16:28
2

With respect to the answers given, the one I liked best was simply adding a "classpathDependencyExcludes" to my failsafe-plugin execution ...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <includes>
                            <include>**/integration/**</include>
                        </includes>
                        <systemPropertyVariables>
                            <tomcat.port>${tomcat.servlet.port}</tomcat.port>
                            <project.artifactId>${project.artifactId}</project.artifactId>
                        </systemPropertyVariables>
                        <classpathDependencyExcludes>
                            <classpathDependencyExcludes>com.google.gwt:gwt-dev</classpathDependencyExcludes>
                        </classpathDependencyExcludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

That ensured that the problematic dependency (in this case gwt-dev), would not appear when running the integration-test phase.

Dave
  • 15,639
  • 133
  • 442
  • 830
0

I would suggest to have separate project(s) with test cases

jnr
  • 790
  • 1
  • 7
  • 9
0

Different dependency sets in Maven profiles are the only way to achieve this, since the "test" scope encloses both "test" and "integration-test" phase.

MaDa
  • 10,511
  • 9
  • 46
  • 84