4

I'm sharing src/test classes between number of modules, in a similar way described in attaching tests guide and the following question.

So, I have the following pom.xml dependencies:

       <dependency>
            <groupId>com.myco.app</groupId>
            <artifactId>foo</artifactId>
        </dependency>

        <dependency>
            <groupId>com.myco.app</groupId>
            <artifactId>foo</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>

BUT, in opposite to the question above, when attaching the test-jar, i don't want to specify the specific test-jar version. As in the compile level dependency:

   <dependency>
      <groupId>com.myco.app</groupId>
      <artifactId>foo</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>

In this case, my pom.xml become erroneous with message about the missing version. Why is this happen? Why i can specify dependency without versions but not the test-jar one? Is there a way to overcome this and make the test-jar to use the latest jar it can find?

8
  • Take a look at this answer to see if fits your needs: stackoverflow.com/questions/30571/… Commented Aug 20, 2015 at 13:36
  • Is this a multi module build? Commented Aug 20, 2015 at 13:36
  • @khmarbaise, yes, it's a multi module build. Commented Aug 20, 2015 at 13:40
  • @PauloSantos thanks, it's a good source. But my question is beyond that - I want to understand why in the first place, defining dependency without version don't work in my case (even if it's not a recommended practice). Commented Aug 20, 2015 at 13:46
  • 1
    Specifying dependencies without version won't work because maven was designed that way. But it works only for plugins, maven will use the latest version when you don't specify the plugin <version>. The only case that I'm aware that allow you use a dependency without version, is when you have the dependency already defined (with version) in a <dependecyManagement> tag Commented Aug 20, 2015 at 13:56

1 Answer 1

5

The reason the main code dependency could be used without the version, is the existence of a "main pom" in our project that automatically generates appropriate version for each dependency in section. Therefore, each dependency can be specified without specific version number.

Test-jar dependency on the other hand, don't have it's version defined anywhere else in the transitive dependency so, the specific version must be specified.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.