[Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes,mavenshadeplugin

來源:互聯網
上載者:User

[Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes,mavenshadeplugin

 連結地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html)

apache網站在國內開啟太慢了。因此我將這些有用的資源收集起來,儲存在部落格中!

Apache Maven Shade Plugin:是一個Maven打包的外掛程式。其官網英文定義如下:This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade

001.

1 <project> 2 ... 3 <build> 4 <plugins> 5 <plugin> 6 <groupId>org.apache.maven.plugins</groupId> 7 <artifactId>maven-shade-plugin</artifactId> 8 <version>2.4.3</version> 9 <executions>10 <execution>11 <phase>package</phase>12 <goals>13 <goal>shade</goal>14 </goals>15 <configuration>16 <artifactSet>17 <excludes>18 <exclude>classworlds:classworlds</exclude>19 <exclude>junit:junit</exclude>20 <exclude>jmock:*</exclude>21 <exclude>*:xml-apis</exclude>22 <exclude>org.apache.maven:lib:tests</exclude>23 <exclude>log4j:log4j:jar:</exclude>24 </excludes>25 </artifactSet>26 </configuration>27 </execution>28 </executions>29 </plugin>30 </plugins>31 </build>32 ...33 </project>View Code

002.

1 <project> 2 ... 3 <build> 4 <plugins> 5 <plugin> 6 <groupId>org.apache.maven.plugins</groupId> 7 <artifactId>maven-shade-plugin</artifactId> 8 <version>2.4.3</version> 9 <executions>10 <execution>11 <phase>package</phase>12 <goals>13 <goal>shade</goal>14 </goals>15 <configuration>16 <filters>17 <filter>18 <artifact>junit:junit</artifact>19 <includes>20 <include>junit/framework/**</include>21 <include>org/junit/**</include>22 </includes>23 <excludes>24 <exclude>org/junit/experimental/**</exclude>25 <exclude>org/junit/runners/**</exclude>26 </excludes>27 </filter>28 <filter>29 <artifact>*:*</artifact>30 <excludes>31 <exclude>META-INF/*.SF</exclude>32 <exclude>META-INF/*.DSA</exclude>33 <exclude>META-INF/*.RSA</exclude>34 </excludes>35 </filter>36 </filters>37 </configuration>38 </execution>39 </executions>40 </plugin>41 </plugins>42 </build>43 ...44 </project>View Code

003.

1 <project> 2 ... 3 <build> 4 <plugins> 5 <plugin> 6 <groupId>org.apache.maven.plugins</groupId> 7 <artifactId>maven-shade-plugin</artifactId> 8 <version>2.4.3</version> 9 <executions>10 <execution>11 <phase>package</phase>12 <goals>13 <goal>shade</goal>14 </goals>15 <configuration>16 <minimizeJar>true</minimizeJar>17 </configuration>18 </execution>19 </executions>20 </plugin>21 </plugins>22 </build>23 ...24 </project>View Code

004.

1 <project> 2 ... 3 <build> 4 <plugins> 5 <plugin> 6 <groupId>org.apache.maven.plugins</groupId> 7 <artifactId>maven-shade-plugin</artifactId> 8 <version>2.4.3</version> 9 <executions>10 <execution>11 <phase>package</phase>12 <goals>13 <goal>shade</goal>14 </goals>15 <configuration>16 <minimizeJar>true</minimizeJar>17 <filters>18 <filter>19 <artifact>log4j:log4j</artifact>20 <includes>21 <include>**</include>22 </includes>23 </filter>24 <filter>25 <artifact>commons-logging:commons-logging</artifact>26 <includes>27 <include>**</include>28 </includes>29 </filter>30 </filters> 31 </configuration>32 </execution>33 </executions>34 </plugin>35 </plugins>36 </build>37 ...38 </project>View Code

 

(001)`Shade`官網上的介紹也不多。可能因為其相對比較簡單吧。但是,我這個菜鳥仍然很頭疼如何配置`Shade`。網上的資料比較少,估計也是認為比較簡單吧,沒人撰文詳細介紹`Shade`。所以,官方提供的例子就成為最有價值的資料了。

(002)結合`Shade`源碼,我開始踏上研究如何使用的`Shade`旅程。源碼的獲得比較簡單,為了研究`Shade`可以將其添加到pom.xml的`dependencies`中。當然也可以去官網鏡像下載。

(003)研究任何`Maven Plugin`之前,都應該先看看這篇外掛程式的介紹 [Guide to Configuring Plug-ins](http://maven.apache.org/guides/mini/guide-configuring-plugins.html),這會讓你少走很多彎路(我不會告訴你我是掉坑裡了爬起來才知道的)。

(003001)在這篇官方文檔裡,我首次看到了`Mojo`,這是Maven Plugin使用的一個IOC架構。(當下我並沒有去研究Mojo所以知道的有限也許未來會去研究下。有興趣的朋友可以去搜尋下。)

(003002)`Mojo`中的欄位是和plugin中的配置對應的,如果對例子中的配置很疑惑,就可以翻開源碼中的`Mojo`順藤摸瓜,找到它們的原理。`Shade`中的`Mojo`就是`ShadeMojo.java`了。

(004)end.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.