Excluding “provided” dependencies from Maven assembly

后端 未结 4 1271
长情又很酷
长情又很酷 2020-12-25 13:49

I am trying to use the Maven assembly plugin to build a jar-with-dependencies, except those that have provided scope.

I have copied the jar-with-dependencie

4条回答
  •  时光说笑
    2020-12-25 14:38

    This is a bit clunky, but you can use the maven-dependency-plugin to copy/unpack all the dependencies into your project, then use the assembly plugin to do the packaging.

    The copy-dependencies and unpack-dependencies goals both have an optional excludeScope property you can set to omit the provided dependencies. The configuration below copies all dependencies into target/lib, your assembly plugin descriptor can be modified to use a fileSet to include those jars.

    Update: Just tested this to confirm it works. Added the configuration for binding the assembly plugin to the package phase, and the relevant modifications to the assembly descriptor.

    
      org.apache.maven.plugins
      maven-dependency-plugin
      
        
          copy-dependencies
          process-resources
          
            copy-dependencies
          
          
            provided
            ${project.build.directory}/lib
          
        
      
    
    
      maven-assembly-plugin
      2.2-beta-4
      
        
          jar-with-deps
          package
          
            single
          
        
      
      
        
          src/main/assembly/my-assembly.xml
        
      
    
    

    The fileSet section of the my-assembly descriptor would look like this:

    
      
        
          ${project.build.directory}/lib
          /
          
            *.*
          
        
      
    ...
    
    
    

提交回复
热议问题