开发者

How can I make a maven test dependent on a class defined in another project's test?

I have two projects, A, and B. Project A depends on project B. Project B implements several JUnit tests that run properly with maven test. Project B JUnit tests also define some constants that both project A, and B rely on. When I run maven install on project B none of the test classes (namely the constants) make it into the Project B SNAPSHOT jar, so when project A looks for project B's constants it can't find them in project B's SNAPSHOT jar that is installed in my local repo. Is there any way to tell maven to package/install a test SNAPSHOT jar, or something similar so project A can have access to those constants during the test? These constants are开发者_如何学运维 only used in the tests.


  • Simple solution: put the constants in src/main/java and make clear that they're only to be used in test code. Use a short package name like testing.
  • Overengineered solution: put the constants in a separate maven project (POM only maybe?), referenced by both A and B with scope test.


I am not 100% sure if this works, but in a similar situation, I could include a

 <classifier>tests</classifier>

into the dependency declaration.

You can then have A depend on both on the "unqualified" B and B-tests.

Update: Apparently, you should not use classifier:test anymore, but rather type:test-jar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜