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?

Community
  • 1
  • 1
Johnny
  • 14,397
  • 15
  • 77
  • 118
  • Take a look at this answer to see if fits your needs: http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency – Paulo Santos Aug 20 '15 at 13:36
  • Is this a multi module build? – khmarbaise Aug 20 '15 at 13:36
  • @khmarbaise, yes, it's a multi module build. – Johnny Aug 20 '15 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). – Johnny Aug 20 '15 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 . 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 tag – Paulo Santos Aug 20 '15 at 13:56
  • You can simply use `${project.version}` in those cases. – khmarbaise Aug 20 '15 at 16:41
  • @khmarbaise it's a good idea, but, modules version could be different so it could cause a problem. – Johnny Aug 24 '15 at 09:35
  • @PauloSantos, after further investigation that's exactly the reason for that! We have a "main pom", which automatically generates appropriate version for each dependency in section. So, it's the reason i could do this. – Johnny Aug 24 '15 at 09:36

1 Answers1

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.

Johnny
  • 14,397
  • 15
  • 77
  • 118