Where should I put test support code for a Java library

前端 未结 2 972

I have a Maven project which is used as a library in other projects. The setup is pretty standard: src/main with the library code, src/test with te

2条回答
  •  时光说笑
    2021-01-18 11:47

    You can do this with the Maven Jar Plugin

    Maven Jar Plugin

    Since you're using Maven you can just cut a separate artifact of the project that contains the libraries you want to use in foo add the following plugin to create another jar artifact:

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

    This creates a second jar in this project of everything in the src/test directory.

    Test Jars

    You could splice out the stuff in that jar you don't need with some filters.

    Then to use this library you would include this as a dependancy in foo:

     
        your.group
        parent-artifact-id
        1.0.0
        test-jar
        test
     
    

    To separate the projects further you can also create a test only project with your more frameworky test jars.
    See How to create a jar containing test classes (Preferred way) in the Maven Jar Plugin doc

提交回复
热议问题