How can I make the test jar include dependencies in Maven?

后端 未结 6 1787
广开言路
广开言路 2020-12-28 20:05

I have a project with src/main/java and src/test/java structure, and I managed to use maven-jar-plugin to build a jar of the test branch. However, I want to package the test

6条回答
  •  天涯浪人
    2020-12-28 20:13

    I had a similar problem with integration tests I need to run on Hadoop. Our integration tests are located in the test folder of a separate integration test module, so what is required is a test-jar-with-dependencies to make our life easier.

    I'm using the assembly plugin as mentioned by Michael-O. My assembly descriptor is located in src/main/assembly/test-jar-with-dependencies.xml and is a modification of the standard jar-with-dependencies descriptor that's part of the plugin:

    
        test-jar-with-dependencies
        
            jar
        
        false
        
            
                /
                true
                
                true
                true
                test
            
        
    
    

    This assembly relies on the test-jar being created as part of the module build. So I added the following to the module's pom.xml:

    
    
        org.apache.maven.plugins                    
        maven-jar-plugin
        
            
                
                    test-jar
                
            
        
    
    
        org.apache.maven.plugins
        maven-assembly-plugin
        
            
                src/main/assembly/test-jar-with-dependencies.xml
            
        
        
            
                package
                
                    single
                
            
        
    
    

提交回复
热议问题