1

I have a multimodule project and unfortunately tests from one module are depend from tests in another module like below:

Module A
public class TestA {...}
public class SomeClassA {...}

Module B
public class TestB extends TestA {
  private SomeClassA instanceOfA;
     .....
}

There is dependency in module's B pom.xml:

    <dependency>
        <groupId>id</groupId>
        <artifactId>module_A</artifactId>
        <type>jar</type>
        <scope>provided</scope>
    </dependency>

and if I open project settings (ctrl + alt + shift + s) there is module A in module B dependencies tab (it has scope compile if that matters). So it looks like I have valid dependencies, but when I'm trying to run my tests there are multiple errors occur and as I understand the main is the following:

The hierarchy of the type TestB is inconsistent.

Other 2 errors are relate to constructor and it is likely that they are consequences of the hierarchy messup.

The same tests are perfectly runs from eclipse if I do export module A in module B and run my test with classpath pointed to module B with checked «add exported…» and «add required…».

Is it possible to import one module with all libraries into another in IDEA?

Software Engineer
  • 13,509
  • 5
  • 57
  • 83
nmax
  • 45
  • 1
  • 5
  • Your maven configuration is incorrect. You need to export the tests from module A as a separate library (jar), then have a test dependency on it in module B. In your dependency above, the jar type is the default, so it isn't necessary. Eclipse is misbehaving with respect to your pom, and you're getting confused because of this. IntelliJ is acting correctly. Finally, this question has nothing to do with your IDE, it's a maven question on configuring test dependencies. The second answer here will provide a solution: http://stackoverflow.com/questions/174560/sharing-test-code-in-maven#174670 – Software Engineer Jul 14 '14 at 18:19
  • 1
    @EngineerDollery I'll accept your answer if you'll form it as answer – nmax Jul 19 '14 at 16:40

1 Answers1

0

The problem here is eclipse, being too lenient with your project build, compared to maven and IntelliJ. Eclipse will work things out for itself, in order to help you out it'll even work out things that you haven't told it to do in the POM. IntelliJ tries to work with the POM as is, and doesn't second guess it. It's up to you to work out for yourself which approach is ultimately more helpful. Personally, I want portable builds, so I prefer the IntelliJ approach.

In this case, you should export the tests from Module A as a separate test-jar, and have Module B depend on it with a test dependency. I won't go into detail as to how to achieve this here, as it's well documented in this question.

Your final question is a separate concern, and should be placed in a separate question with more detail. You may be looking for a POM import, or how to use the Shade plugin.

Finally, I'd avoid using scopes other than test initially during development. You can get into a lot of trouble with provided as it not only means that your container provides the library, but also that you don't accept transitive dependencies -- and both of these things can cause unexpected side effects.

Community
  • 1
  • 1
Software Engineer
  • 13,509
  • 5
  • 57
  • 83