Maven: How to handle generated sources for test(only)?

后端 未结 1 1746
失恋的感觉
失恋的感觉 2020-12-31 13:49

Usually generated sources should be created in the target dir. But how do I handle classes that are only used for test? I dont want that these classes get packaged in my jar

1条回答
  •  余生分开走
    2020-12-31 14:00

    Use maven build helper plugin's add-test-source goal to add your generated test source files to the build -> http://mojo.codehaus.org/build-helper-maven-plugin/add-test-source-mojo.html

    It ensures that the directories added by this goal will be picked up automatically by the compiler plugin during test-compile phase of the build.

    EDIT

    Here is the example of how to generate code for testign with cxf-codegen-plugin

    
      
        ...
        
          org.apache.cxf
          cxf-codegen-plugin
          ${cxf.version}
          
            
              generate-test-sources
              generate-test-sources
              
                ${project.build.directory}/generated/cxf
                
                  
                    ${basedir}/src/main/wsdl/myService.wsdl
                  
                
              
              
                wsdl2java
              
            
          
        
        
          org.codehaus.mojo
          build-helper-maven-plugin
          ${build-helper-maven-plugin.version}
          
            
              add-test-sources
              generate-test-sources
              
                add-test-source
              
              
                
                  ${project.build.directory}/generated/cxf
                
              
            
          
        
        ...
      
    
    

    0 讨论(0)
提交回复
热议问题