1

I would like to include (maven) dependencies in my war while making sure that they are not in the runtime or test scope.

The problem is the following:

  1. There a number of jars (let's say jar A, B, and C) that I need in my war. This is because of the use of CDI.

  2. I have a number of integration tests that use the war produced by the project. These integration tests are arquillian based tests.

  3. However, I have other tests that are not integration tests that will be adversely affected by the inclusion of jars A, B and C on the class path.

14
  • 3
    See you main options here. There does not seem to be one that does what you want. Commented Apr 4, 2013 at 13:02
  • 2
    @Marco, have you taken a look at using Shrinkwrap to dynamically create test archives? Commented Apr 4, 2013 at 13:09
  • 1
    Explain how a dependency would adversely affect other tests? Please edit your question with the response, don't leave it as another comment so everyone will read it without having to dig through the comments section. Commented Apr 4, 2013 at 13:12
  • 3
    @Marco - Shrinkwrap allows you to dynamically build a WAR containing pretty much anything you want. It can pull Maven dependencies or standalone resources in your classpath. If that doesn't fit your requirement then you might want to expand on what those requirements are. Commented Apr 4, 2013 at 13:14
  • 1
    @Marco - sorry, perhaps I read the question wrong. It sounds like what you're looking for is a scope that is part of compile, but not test. Have you tried the answer suggested in this SO question: stackoverflow.com/questions/12053316/… Commented Apr 8, 2013 at 12:46

4 Answers 4

4

war is not a dependency scope. Valid scopes are provided, compile, runtime, test, system. You can select only one of those, they are the only options and none of them exclude from the test scope.

Sign up to request clarification or add additional context in comments.

Comments

0

You have attribute with several options: runtime, test, compile, etc.

For example:

<dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>${org.slf4j.version}</version> <scope>runtime</scope> </dependency> 

More you can read here.

1 Comment

Unfortunately, runtime scope means that the dependency is also available in test scope. Please reread the question!
0

You can specify the scope in the dependencies section like below. It can be mentioned as test, compile or runtime.

 <dependency> <groupId>org.springframework.integration</groupId> <artifactId>org.springframework.integration.adapter</artifactId> <version>1.0.3.RELEASE</version> <scope>runtime</scope> </dependency> 

Hope this helps. Thanks, KJ

1 Comment

As I mention above, runtime scope means that the dependency is also available in test scope, which is precisely what I do not want.
0

Good options:

Ah HA! It's possible to exclude certain dependencies from the test phase by using the surefire-plugin. That's described in this StackOverflow answer.

This way I can create my war and not have the dependencies in the test scope (thanks Peter Mularien)!

Bad options:

It looks like the maven assembly plugin requires you to have any include dependencies also available in a dependency scope. Since test is the smallest scope, it's impossible to include a dependency in your war without having it also be available on the test scope of the project.

The maven war plugin does not allow you to include (or exclude) dependencies.

Another other option is to create a second "distribution" module that includes the needed dependencies in it's pom. However, that means that the arquillian test is then referencing the previous build's war -- which is also not ideal.

Yet another option is to use Shrinkwrap to create a jar with tests and fork the JVM to run the "test" jar -- I've done this before when I needed to test my code with multiple ORM's (otherwise, having OpenJPA in your path conflicts with having Hibernate in your path, for example). But that disconnects your tests from your test framework (JUnit, TestNG, etc.) and makes the tests hard to debug.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.