Difference between maven plugins ( assembly-plugins , jar-plugins , shaded-plugins)

前端 未结 3 2157
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 08:59

I am a beginner in maven and now I\'m confused with the difference between these maven plugins. Is these all create jar files? now my questions are

  1. what\'s

3条回答
  •  甜味超标
    2020-12-04 09:59

    Jar plugin

    Let's see what the following command can tell.

    mvn help:describe -Dplugin=org.apache.maven.plugins:maven-jar-plugin

    It has 3 goals, help, jar and test-jar. I believe you are mostly interested in the jar goal, which according to the description does the following:

    Build a JAR from the current project.

    As a side note, executing mvn help:effective-pom on a project with packaging set to jar, shows that this plugin is automatically configured and gets executed during the package phase.

      
        maven-jar-plugin
        2.4
        
          
            default-jar
            package
            
              jar
            
          
        
      
    

    Assembly plugin

    This one serves a different purpose. It has 8 goals, but 6 of them are deprecated. So apart from the help goal, this leaves us with the single goal.

    mvn help:describe -Dplugin=org.apache.maven.plugins:maven-assembly-plugin

    Assemble an application bundle or distribution from an assembly descriptor. This goal is suitable either for binding to the lifecycle or calling directly from the command line (provided all required files are available before the build starts, or are produced by another goal specified before this one on the command line).

    You may use the assembly plugin when you want to deliver more than your project's artifact (JAR, WAR, etc.), but the configuration goes in another file.

    Shade plugin

    The description of the main goal is a bit disappointing.

    mvn help:describe -Dplugin=org.apache.maven.plugins:maven-shade-plugin

    Mojo that performs shading delegating to the Shader component.

    You mostly want to use this plugin if you want to produce an uber-jar, which is your artifact in a JAR with all its transitive dependencies in it.

    Basicly, if you're building a library, you'll stick with the default JAR plugin. If you're building an application, you could consider using the shade plugin, though to me, it's kind of quick and dirty. If uber-jar is not your taste or the distribution cannot fit inside a single JAR (external configuration, native dependencies, etc.) then you should go for the assembly plugin.

提交回复
热议问题