Sharing src/test classes with Maven without version specification for test-jar

末鹿安然 提交于 2019-12-12 09:47:33

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32119591/sharing-src-test-classes-with-maven-without-version-specification-for-test-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!