Sharing src/test classes between modules in a multi-module maven project

前端 未结 2 1379
醉酒成梦
醉酒成梦 2020-12-02 07:34

I have a multi-module Maven project. For the sake of this example, consider two modules:

  • data
  • consumer

Modul

2条回答
  •  青春惊慌失措
    2020-12-02 08:14

    Your Consumer project depends upon your Data project, therefore we are happy that Data must be built prior to Consumer. As a result, using the techniques suggested in the comments, I would ensure your Data project contains all the test code that you wish to share and configure the POM to produce a test JAR:

    
      org.apache.maven.plugins
      maven-jar-plugin
      2.2
      
        
          
            test-jar
          
        
      
    
    

    Your Consumer project would then depend upon both the normal Data JAR artifact, plus the additional test-jar artifact, with test scope of course:

    
      com.foo
      data
      1.0
      test-jar
      test
    
    

    I've used this approach on many occasions and it works well.

提交回复
热议问题