Modified: maven/website/components/plugins-archives/maven-shade-plugin-LATEST/examples/resource-transformers.html ============================================================================== --- maven/website/components/plugins-archives/maven-shade-plugin-LATEST/examples/resource-transformers.html (original) +++ maven/website/components/plugins-archives/maven-shade-plugin-LATEST/examples/resource-transformers.html Thu Mar 24 18:14:26 2022 @@ -1,681 +1,665 @@ -<!DOCTYPE html> -<!-- - | Generated by Apache Maven Doxia Site Renderer 1.8.1 at 2021-07-14 - | Rendered using Apache Maven Fluido Skin 1.6 ---> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <head> - <meta charset="UTF-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <meta name="author" content="Mauro Talevi" /> - <meta name="Date-Creation-yyyymmdd" content="20080721" /> - <meta name="Date-Revision-yyyymmdd" content="20210714" /> - <meta http-equiv="Content-Language" content="en" /> - <title>Apache Maven Shade Plugin – Resource Transformers</title> - <link rel="stylesheet" href="../css/apache-maven-fluido-1.6.min.css" /> - <link rel="stylesheet" href="../css/site.css" /> - <link rel="stylesheet" href="../css/print.css" media="print" /> - <script type="text/javascript" src="../js/apache-maven-fluido-1.6.min.js"></script> - <!-- Google Analytics --> - <script type="text/javascript"> - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-140879-1']); - _gaq.push(['_trackPageview']); - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); - </script> - </head> - <body class="topBarDisabled"> - <div class="container-fluid"> - <div id="banner"> - <div class="pull-left"><a href="http://www.apache.org/" id="bannerLeft"><img src="http://maven.apache.org/images/apache-maven-project.png" /></a></div> - <div class="pull-right"><a href="http://maven.apache.org/" id="bannerRight"><img src="http://maven.apache.org/images/maven-logo-black-on-white.png" /></a></div> - <div class="clear"><hr/></div> - </div> - - <div id="breadcrumbs"> - <ul class="breadcrumb"> - <li class=""><a href="https://www.apache.org/" class="externalLink" title="Apache">Apache</a><span class="divider">/</span></li> - <li class=""><a href="../../../index.html" title="Maven">Maven</a><span class="divider">/</span></li> - <li class=""><a href="../../index.html" title="Plugins">Plugins</a><span class="divider">/</span></li> - <li class=""><a href="../index.html" title="Apache Maven Shade Plugin">Apache Maven Shade Plugin</a><span class="divider">/</span></li> - <li class="active ">Resource Transformers</li> - <li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2021-07-14</li> - <li id="projectVersion" class="pull-right">Version: 3.3.1-SNAPSHOT</li> - </ul> - </div> - <div class="row-fluid"> - <div id="leftColumn" class="span2"> - <div class="well sidebar-nav"> -<ul class="nav nav-list"> - <li class="nav-header">Overview</li> - <li><a href="../index.html" title="Introduction"><span class="none"></span>Introduction</a> </li> - <li><a href="../plugin-info.html" title="Goals"><span class="none"></span>Goals</a> </li> - <li><a href="../usage.html" title="Usage"><span class="none"></span>Usage</a> </li> - <li><a href="../faq.html" title="FAQ"><span class="none"></span>FAQ</a> </li> - <li><a href="http://www.apache.org/licenses/" class="externalLink" title="License"><span class="none"></span>License</a> </li> - <li><a href="../download.html" title="Download"><span class="none"></span>Download</a> </li> - <li class="nav-header">Examples</li> - <li><a href="../examples/includes-excludes.html" title="Selecting Contents for Uber JAR"><span class="none"></span>Selecting Contents for Uber JAR</a> </li> - <li><a href="../examples/class-relocation.html" title="Relocating Classes"><span class="none"></span>Relocating Classes</a> </li> - <li><a href="../examples/attached-artifact.html" title="Attaching the Shaded Artifact"><span class="none"></span>Attaching the Shaded Artifact</a> </li> - <li><a href="../examples/executable-jar.html" title="Executable JAR"><span class="none"></span>Executable JAR</a> </li> - <li class="active"><a href="#"><span class="none"></span>Resource Transformers</a> - </li> - <li><a href="../examples/use-shader-other-impl.html" title="Using another Shader implementation"><span class="none"></span>Using another Shader implementation</a> </li> - <li class="nav-header">Project Documentation</li> - <li><a href="../project-info.html" title="Project Information"><span class="icon-chevron-right"></span>Project Information</a> </li> - <li><a href="../project-reports.html" title="Project Reports"><span class="icon-chevron-right"></span>Project Reports</a> </li> - <li class="nav-header">Maven Projects</li> - <li><a href="../../../archetype/index.html" title="Archetype"><span class="none"></span>Archetype</a> </li> - <li><a href="../../../resolver/index.html" title="Artifact Resolver"><span class="none"></span>Artifact Resolver</a> </li> - <li><a href="../../../doxia/index.html" title="Doxia"><span class="none"></span>Doxia</a> </li> - <li><a href="../../../jxr/index.html" title="JXR"><span class="none"></span>JXR</a> </li> - <li><a href="../../../ref/current" title="Maven"><span class="none"></span>Maven</a> </li> - <li><a href="../../../pom/index.html" title="Parent POMs"><span class="none"></span>Parent POMs</a> </li> - <li><a href="../../index.html" title="Plugins"><span class="none"></span>Plugins</a> </li> - <li><a href="../../../plugin-testing/index.html" title="Plugin Testing"><span class="none"></span>Plugin Testing</a> </li> - <li><a href="../../../plugin-tools/index.html" title="Plugin Tools"><span class="none"></span>Plugin Tools</a> </li> - <li><a href="../../../apache-resource-bundles/index.html" title="Resource Bundles"><span class="none"></span>Resource Bundles</a> </li> - <li><a href="../../../scm/index.html" title="SCM"><span class="none"></span>SCM</a> </li> - <li><a href="../../../shared/index.html" title="Shared Components"><span class="none"></span>Shared Components</a> </li> - <li><a href="../../../skins/index.html" title="Skins"><span class="none"></span>Skins</a> </li> - <li><a href="../../../surefire/index.html" title="Surefire"><span class="none"></span>Surefire</a> </li> - <li><a href="../../../wagon/index.html" title="Wagon"><span class="none"></span>Wagon</a> </li> - <li class="nav-header">ASF</li> - <li><a href="https://www.apache.org/foundation/how-it-works.html" class="externalLink" title="How Apache Works"><span class="none"></span>How Apache Works</a> </li> - <li><a href="https://www.apache.org/foundation/" class="externalLink" title="Foundation"><span class="none"></span>Foundation</a> </li> - <li><a href="https://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsoring Apache"><span class="none"></span>Sponsoring Apache</a> </li> - <li><a href="https://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks"><span class="none"></span>Thanks</a> </li> - </ul> -<form id="search-form" action="https://www.google.com/search" method="get" > - <input value="$sitesearchValue" name="sitesearch" type="hidden"/> - <input class="search-query" name="q" id="query" type="text" /> -</form> -<script type="text/javascript">asyncJs( 'https://cse.google.com/brand?form=search-form' )</script> - <hr /> - <div id="poweredBy"> - <script type="text/javascript">asyncJs( 'https://apis.google.com/js/plusone.js' )</script> - <div class="g-plusone" data-href="https://maven.apache.org/plugins/maven-shade-plugin/" data-size="tall" ></div> - <div class="clear"></div> - <div class="clear"></div> - <div id="twitter"> - <a href="https://twitter.com/ASFMavenProject" class="twitter-follow-button" data-show-count="false" data-align="left" data-size="medium" data-show-screen-name="true" data-lang="en">Follow ASFMavenProject</a> - <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> - </div> - <div class="clear"></div> - <div class="clear"></div> - <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a> - </div> - </div> - </div> - <div id="bodyColumn" class="span10" > -<div class="section"> -<h2><a name="Resource_Transformers"></a>Resource Transformers</h2> -<p>Aggregating classes/resources from several artifacts into one uber JAR is straight forward as long as there is no overlap. Otherwise, some kind of logic to merge resources from several JARs is required. This is where resource transformers kick in.</p> -<table border="1" class="table table-striped"><caption>Transformers in <tt>org.apache.maven.plugins.shade.resource</tt> -</caption> -<tr class="a"> -<td align="left"><a href="#ApacheLicenseResourceTransformer">ApacheLicenseResourceTransformer</a></td> -<td align="left">Prevents license duplication</td></tr> -<tr class="b"> -<td align="left"><a href="#ApacheNoticeResourceTransformer">ApacheNoticeResourceTransformer</a></td> -<td align="left">Prepares merged NOTICE</td></tr> -<tr class="a"> -<td align="left"><a href="#AppendingTransformer">AppendingTransformer</a></td> -<td align="left">Adds content to a resource</td></tr> -<tr class="b"> -<td align="left"><a href="#ComponentsXmlResourceTransformer">ComponentsXmlResourceTransformer</a></td> -<td align="left">Aggregates Plexus <tt>components.xml</tt></td></tr> -<tr class="a"> -<td align="left"><a href="#DontIncludeResourceTransformer">DontIncludeResourceTransformer</a></td> -<td align="left">Prevents inclusion of matching resources</td></tr> -<tr class="b"> -<td align="left"><a href="#GroovyResourceTransformer">GroovyResourceTransformer</a></td> -<td align="left">Merges Apache Groovy extends modules</td></tr> -<tr class="a"> -<td align="left"><a href="#IncludeResourceTransformer">IncludeResourceTransformer</a></td> -<td align="left">Adds files from the project</td></tr> -<tr class="b"> -<td align="left"><a href="#ManifestResourceTransformer">ManifestResourceTransformer</a></td> -<td align="left">Sets entries in the <tt>MANIFEST</tt></td></tr> -<tr class="a"> -<td align="left"><a href="#PluginXmlResourceTransformer">PluginXmlResourceTransformer</a></td> -<td align="left">Aggregates Mavens <tt>plugin.xml</tt></td></tr> -<tr class="b"> -<td align="left"><a href="#ResourceBundleAppendingTransformer">ResourceBundleAppendingTransformer</a></td> -<td align="left">Merges ResourceBundles</td></tr> -<tr class="a"> -<td align="left"><a href="#ServicesResourceTransformer">ServicesResourceTransformer</a></td> -<td align="left">Relocated class names in <tt>META-INF/services</tt> resources and merges them.</td></tr> -<tr class="b"> -<td align="left"><a href="#XmlAppendingTransformer">XmlAppendingTransformer</a></td> -<td align="left">Adds XML content to an XML resource</td></tr></table> -<table border="1" class="table table-striped"><caption>Transformers in <tt>org.apache.maven.plugins.shade.resource.properties</tt> (available since 3.2.2)</caption> -<tr class="a"> -<td align="left"><a href="#PropertiesTransformer">PropertiesTransformer</a></td> -<td align="left">Merges properties files owning an ordinal to solve conflicts</td></tr> -<tr class="b"> -<td align="left"><a href="#OpenWebBeansPropertiesTransformer">OpenWebBeansPropertiesTransformer</a></td> -<td align="left">Merges Apache OpenWebBeans configuration files</td></tr> -<tr class="a"> -<td align="left"><a href="#MicroprofileConfigTransformer">MicroprofileConfigTransformer</a></td> -<td align="left">Merges conflicting Microprofile Config properties based on an ordinal</td></tr></table> -<div class="section"> -<h3><a name="Merging_Plexus_Component_Descriptors_with_the_ComponentsXmlResourceTransformer"></a>Merging Plexus Component Descriptors with the <a name="ComponentsXmlResourceTransformer">ComponentsXmlResourceTransformer</a></h3> -<p>JARs for components targeting the Plexus IoC container contain a <tt>META-INF/plexus/components.xml</tt> entry that declares the component and its requirements. If the uber JAR aggregates multiple Plexus components, a <tt>ComponentsXmlResourceTransformer</tt> needs to be used to merge the XML descriptors:</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div> -<p>Since plugin version 1.3, this resource transformer will also update the descriptor to account for relocation of component interfaces/implementations (if any).</p></div> -<div class="section"> -<h3><a name="Relocate_classes_of_the_Maven_Plugin_Descriptor_with_the_PluginXmlResourceTransformer"></a>Relocate classes of the Maven Plugin Descriptor with the <a name="PluginXmlResourceTransformer">PluginXmlResourceTransformer</a></h3> -<p>With <a class="externalLink" href="http://maven.apache.org/plugin-tools/index.html">Plugin Tools 3.0</a> annotations have been introduced. Now references to classes are no longer classnames as String, but the actual Class reference. When you wanted to relocate classes, you had to maintain the <tt>META-INF/maven/plugin.xml</tt> by hand, but now this can be done with the <tt>PluginXmlResourceTransformer</tt> </p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer"/> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h3><a name="Concatenating_Service_Entries_with_the_ServicesResourceTransformer"></a>Concatenating Service Entries with the <a name="ServicesResourceTransformer">ServicesResourceTransformer</a></h3> -<p>JAR files providing implementations of some interfaces often ship with a <tt>META-INF/services/</tt> directory that maps interfaces to their implementation classes for lookup by the service locator. To relocate the class names of these implementation classes, and to merge multiple implementations of the same interface into one service entry, the <tt>ServicesResourceTransformer</tt> can be used:</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h3><a name="Merging_Content_of_Specific_Files_with_AppendingTransformer.2C_XmlAppendingTransformer_and_ResourceBundleAppendingTransformer"></a>Merging Content of Specific Files with <a name="AppendingTransformer">AppendingTransformer</a>, XmlAppendingTransformer and ResourceBundleAppendingTransformer</h3> -<p>Some jars contain additional resources (such as properties files) that have the same file name. To avoid overwriting, you can opt to merge them by appending their content into one file. One good example for this is when aggregating both the spring-context and plexus-spring jars. Both of them have the <tt>META-INF/spring.handlers</tt> file which is used by Spring to handle XML schema namespaces. You can merge the contents of all the files with that specific name using the <tt>AppendingTransformer</tt> as shown below:</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> - <resource>META-INF/spring.handlers</resource> - </transformer> - <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> - <resource>META-INF/spring.schemas</resource> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div> -<p>For XML files, you can use the <tt><a name="XmlAppendingTransformer">XmlAppendingTransformer</a></tt> instead:</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> - <resource>META-INF/magic.xml</resource> - <!-- Add this to enable loading of DTDs - <ignoreDtd>false</ignoreDtd> - --> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div> -<p>Since plugin version 1.3.1, the <tt>XmlAppendingTransformer</tt> will by default not load DTDs, thereby avoiding network access. The potential downside of this mode is that external entities cannot be resolved which could fail the transformation, e.g. when using the Crimson XML parser as used in some JRE 1.4. If the transformed resource uses external entities, DTD resolution can either be turned back on or a plugin dependency on <tt>xerces:xercesImpl:2.9.1</tt> is added to the POM.</p> -<p>For ResourceBundles properties files, you can use the <tt><a name="ResourceBundleAppendingTransformer">ResourceBundleAppendingTransformer</a></tt> instead, which will respect all available Locales as well:</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ResourceBundleAppendingTransformer"> - <!-- the base name of the resource bundle, a fully qualified class name --> - <basename>path/to/Messages</basename> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h3><a name="Excluding_Resources_with_the_DontIncludeResourceTransformer"></a>Excluding Resources with the <a name="DontIncludeResourceTransformer">DontIncludeResourceTransformer</a></h3> -<p>The <tt>DontIncludeResourceTransformer</tt> allows resources to be excluded when their name ends in a given value.</p> -<p>For example, the following sample excludes all resources ending in <tt>.txt</tt>.</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> - <resource>.txt</resource> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div> -<p>Since maven-shade-plugin-3.0 it is also possible to give a list of resources which should not be included, like: </p> -<div class="source"><pre class="prettyprint linenums"><transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> - <resources> - <resource>.txt</resource> - <resource>READ.me</resource> - </resources> -</transformer> -</pre></div></div> -<div class="section"> -<h3><a name="Adding_New_Resources_with_the_IncludeResourceTransformer"></a>Adding New Resources with the <a name="IncludeResourceTransformer">IncludeResourceTransformer</a></h3> -<p>The <tt>IncludeResourceTransformer</tt> allows project files to be included in the package under a given name.</p> -<p>For example, the following sample includes <tt>README.txt</tt> in the package as <tt>README</tt> in the <tt>META-INF</tt> directory.</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> - <resource>META-INF/README</resource> - <file>README.txt</file> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h3><a name="Setting_Manifest_Entries_with_the_ManifestResourceTransformer"></a>Setting Manifest Entries with the <a name="ManifestResourceTransformer">ManifestResourceTransformer</a></h3> -<p>The <tt>ManifestResourceTransformer</tt> allows existing entries in the <tt>MANIFEST</tt> to be replaced and new entries added. </p> -<p>For example, the following sample sets</p> -<ul> -<li>the <tt>Main-Class</tt> entry to the value of the <tt>app.main.class</tt> property,</li> -<li>the <tt>X-Compile-Source-JDK</tt> entry to the value of the <tt>maven.compile.source</tt> property and</li> -<li>the <tt>X-Compile-Target-JDK</tt> entry to the value of the <tt>maven.compile.target</tt> property.</li></ul> -<p>By default the <tt>ManifestResourceTransformer</tt> will relocate the following attributes:</p> -<ul> -<li>Export-Package</li> -<li>Import-Package</li> -<li>Provide-Capability</li> -<li>Require-Capability</li></ul> -<p>With <tt>additionalAttributes</tt> you can specify the attributes that need to be relocated too.</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <manifestEntries> - <Main-Class>${app.main.class}</Main-Class> - <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK> - <X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK> - </manifestEntries> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h3><a name="Licensing"></a>Licensing</h3> -<div class="section"> -<h4><a name="Preventing_License_Duplication_with_the_ApacheLicenseResourceTransformer"></a>Preventing License Duplication with the <a name="ApacheLicenseResourceTransformer">ApacheLicenseResourceTransformer</a></h4> -<p>Some open source producers (including the <a class="externalLink" href="https://www.apache.org"> Apache Software Foundation</a>) include a copy of their license in the META-INF directory. These are conventionally named either <tt>LICENSE</tt>,<tt>LICENSE.txt</tt> or <tt>LICENSE.md</tt>. When merging these dependencies, adding these resources may cause confusion. The <tt>ApacheLicenseResourceTransformer</tt> ensures that duplicate licenses (named according to this convention) are not merged. </p> -<p>For example, the following prevents the license from a <tt>commons-collections</tt> dependency being merged in</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h4><a name="Aggregating_Notices_with_the_ApacheNoticeResourceTransformer"></a>Aggregating Notices with the <a name="ApacheNoticeResourceTransformer">ApacheNoticeResourceTransformer</a></h4> -<p>Some licenses (including the <a class="externalLink" href="https://www.apache.org/licenses/LICENSE-2.0.html"> Apache License, Version 2</a>) require that notices are preserved by downstream distributors. <tt>ApacheNoticeResourceTransformer</tt> automates the assembly of an appropriate <tt>NOTICE</tt>.</p> -<p>For example, to simply merge in dependent notices:</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer"> - <addHeader>false</addHeader> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h4><a name="Aggregating_Apache_Groovy_extension_modules_descriptors_with_the_GroovyResourceTransformer"></a>Aggregating Apache Groovy extension modules descriptors with the <a name="GroovyResourceTransformer">GroovyResourceTransformer</a></h4> -<p>The Apache Groovy language provides extension modules located at <tt>META-INF/services/org.codehaus.groovy.runtime.ExtensionModule</tt>, these modules use the property file format. <tt>GroovyResourceTransformer</tt> automates the assembly of Groovy extension modules <tt>NOTICE</tt>.</p> -<p>For example, to simply merge the extension modules of several jars:</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.GroovyResourceTransformer"> - <extModuleName>the-aggregated-module</extModuleName> - <extModuleVersion>1.0.0</extModuleVersion> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div></div> -<div class="section"> -<h3><a name="Merging_properties_files_with_PropertiesTransformer"></a>Merging properties files with <a name="PropertiesTransformer">PropertiesTransformer</a></h3> -<p>The <tt>PropertiesTransformer</tt> allows a set of properties files to be merged and to resolve conflicts based on an ordinal giving the priority of each file. An optional <tt>alreadyMergedKey</tt> enables to have a boolean flag in the file which, if set to true, request to use the file as it as the result of the merge. If two files are considered complete in the merge process then the shade will fail.</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.properties.PropertiesTransformer"> - <!-- required configuration --> - <resource>configuration/application.properties</resource> - <ordinalKey>ordinal</ordinalKey> - <!-- optional configuration --> - <alreadyMergedKey>already_merged</alreadyMergedKey> - <defaultOrdinal>0</defaultOrdinal> - <reverseOrder>false</reverseOrder> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h3><a name="Merging_Apache_OpenWebBeans_configuration_with_OpenWebBeansPropertiesTransformer"></a>Merging Apache OpenWebBeans configuration with <a name="OpenWebBeansPropertiesTransformer">OpenWebBeansPropertiesTransformer</a></h3> -<p><tt>OpenWebBeansPropertiesTransformer</tt> preconfigure a <tt>PropertiesTransformer</tt> for Apache OpenWebBeans configuration files.</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.properties.OpenWebBeansPropertiesTransformer" /> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div> -<div class="section"> -<h3><a name="Merging_Microprofile_Config_properties_with_MicroprofileConfigTransformer"></a>Merging Microprofile Config properties with <a name="MicroprofileConfigTransformer">MicroprofileConfigTransformer</a></h3> -<p><tt>MicroprofileConfigTransformer</tt> preconfigure a <tt>PropertiesTransformer</tt> for Microprofile Config. The only required configuration is the ordinal. The <tt>alreadyMergedKey</tt> is supported but is not defined by the specification.</p> -<div class="source"><pre class="prettyprint linenums"><project> - ... - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.3.1-SNAPSHOT</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.properties.MicroprofileConfigTransformer"> - <resource>configuration/app.properties</resource> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - ... -</project> -</pre></div></div></div> - </div> - </div> - </div> - <hr/> - <footer> - <div class="container-fluid"> - <div class="row-fluid"> - <p>Copyright ©2002–2021 -<a href="https://www.apache.org/">The Apache Software Foundation</a>. -All rights reserved.</p> - </div> - </div> - </footer> - </body> +<!DOCTYPE html> +<!-- + | Generated by Apache Maven Doxia Site Renderer 1.8.1 at 2022-03-24 + | Rendered using Apache Maven Fluido Skin 1.6 +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta charset="UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="author" content="Mauro Talevi" /> + <meta name="Date-Creation-yyyymmdd" content="20080721" /> + <meta name="Date-Revision-yyyymmdd" content="20220324" /> + <meta http-equiv="Content-Language" content="en" /> + <title>Apache Maven Shade Plugin – Resource Transformers</title> + <link rel="stylesheet" href="../css/apache-maven-fluido-1.6.min.css" /> + <link rel="stylesheet" href="../css/site.css" /> + <link rel="stylesheet" href="../css/print.css" media="print" /> + <script type="text/javascript" src="../js/apache-maven-fluido-1.6.min.js"></script> + <!-- Google Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-140879-1']); + _gaq.push(['_trackPageview']); + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + </head> + <body class="topBarDisabled"> + <div class="container-fluid"> + <div id="banner"> + <div class="pull-left"><a href="http://www.apache.org/" id="bannerLeft"><img src="http://maven.apache.org/images/apache-maven-project.png" /></a></div> + <div class="pull-right"><a href="http://maven.apache.org/" id="bannerRight"><img src="http://maven.apache.org/images/maven-logo-black-on-white.png" /></a></div> + <div class="clear"><hr/></div> + </div> + + <div id="breadcrumbs"> + <ul class="breadcrumb"> + <li class=""><a href="https://www.apache.org/" class="externalLink" title="Apache">Apache</a><span class="divider">/</span></li> + <li class=""><a href="../../../index.html" title="Maven">Maven</a><span class="divider">/</span></li> + <li class=""><a href="../../index.html" title="Plugins">Plugins</a><span class="divider">/</span></li> + <li class=""><a href="../index.html" title="Apache Maven Shade Plugin">Apache Maven Shade Plugin</a><span class="divider">/</span></li> + <li class="active ">Resource Transformers</li> + <li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2022-03-24</li> + <li id="projectVersion" class="pull-right">Version: 3.3.0</li> + </ul> + </div> + <div class="row-fluid"> + <div id="leftColumn" class="span2"> + <div class="well sidebar-nav"> +<ul class="nav nav-list"> + <li class="nav-header">Overview</li> + <li><a href="../index.html" title="Introduction"><span class="none"></span>Introduction</a> </li> + <li><a href="../plugin-info.html" title="Goals"><span class="none"></span>Goals</a> </li> + <li><a href="../usage.html" title="Usage"><span class="none"></span>Usage</a> </li> + <li><a href="../faq.html" title="FAQ"><span class="none"></span>FAQ</a> </li> + <li><a href="http://www.apache.org/licenses/" class="externalLink" title="License"><span class="none"></span>License</a> </li> + <li><a href="../download.html" title="Download"><span class="none"></span>Download</a> </li> + <li class="nav-header">Examples</li> + <li><a href="../examples/includes-excludes.html" title="Selecting Contents for Uber JAR"><span class="none"></span>Selecting Contents for Uber JAR</a> </li> + <li><a href="../examples/class-relocation.html" title="Relocating Classes"><span class="none"></span>Relocating Classes</a> </li> + <li><a href="../examples/attached-artifact.html" title="Attaching the Shaded Artifact"><span class="none"></span>Attaching the Shaded Artifact</a> </li> + <li><a href="../examples/executable-jar.html" title="Executable JAR"><span class="none"></span>Executable JAR</a> </li> + <li class="active"><a href="#"><span class="none"></span>Resource Transformers</a> + </li> + <li><a href="../examples/use-shader-other-impl.html" title="Using another Shader implementation"><span class="none"></span>Using another Shader implementation</a> </li> + <li class="nav-header">Project Documentation</li> + <li><a href="../project-info.html" title="Project Information"><span class="icon-chevron-right"></span>Project Information</a> </li> + <li><a href="../project-reports.html" title="Project Reports"><span class="icon-chevron-right"></span>Project Reports</a> </li> + <li class="nav-header">Maven Projects</li> + <li><a href="../../../archetype/index.html" title="Archetype"><span class="none"></span>Archetype</a> </li> + <li><a href="../../../resolver/index.html" title="Artifact Resolver"><span class="none"></span>Artifact Resolver</a> </li> + <li><a href="../../../doxia/index.html" title="Doxia"><span class="none"></span>Doxia</a> </li> + <li><a href="../../../jxr/index.html" title="JXR"><span class="none"></span>JXR</a> </li> + <li><a href="../../../ref/current" title="Maven"><span class="none"></span>Maven</a> </li> + <li><a href="../../../pom/index.html" title="Parent POMs"><span class="none"></span>Parent POMs</a> </li> + <li><a href="../../index.html" title="Plugins"><span class="none"></span>Plugins</a> </li> + <li><a href="../../../plugin-testing/index.html" title="Plugin Testing"><span class="none"></span>Plugin Testing</a> </li> + <li><a href="../../../plugin-tools/index.html" title="Plugin Tools"><span class="none"></span>Plugin Tools</a> </li> + <li><a href="../../../apache-resource-bundles/index.html" title="Resource Bundles"><span class="none"></span>Resource Bundles</a> </li> + <li><a href="../../../scm/index.html" title="SCM"><span class="none"></span>SCM</a> </li> + <li><a href="../../../shared/index.html" title="Shared Components"><span class="none"></span>Shared Components</a> </li> + <li><a href="../../../skins/index.html" title="Skins"><span class="none"></span>Skins</a> </li> + <li><a href="../../../surefire/index.html" title="Surefire"><span class="none"></span>Surefire</a> </li> + <li><a href="../../../wagon/index.html" title="Wagon"><span class="none"></span>Wagon</a> </li> + <li class="nav-header">ASF</li> + <li><a href="https://www.apache.org/foundation/how-it-works.html" class="externalLink" title="How Apache Works"><span class="none"></span>How Apache Works</a> </li> + <li><a href="https://www.apache.org/foundation/" class="externalLink" title="Foundation"><span class="none"></span>Foundation</a> </li> + <li><a href="https://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsoring Apache"><span class="none"></span>Sponsoring Apache</a> </li> + <li><a href="https://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks"><span class="none"></span>Thanks</a> </li> + </ul> +<form id="search-form" action="https://www.google.com/search" method="get" > + <input value="$sitesearchValue" name="sitesearch" type="hidden"/> + <input class="search-query" name="q" id="query" type="text" /> +</form> +<script type="text/javascript">asyncJs( 'https://cse.google.com/brand?form=search-form' )</script> + <hr /> + <div id="poweredBy"> + <script type="text/javascript">asyncJs( 'https://apis.google.com/js/plusone.js' )</script> + <div class="g-plusone" data-href="https://maven.apache.org/plugins/maven-shade-plugin/" data-size="tall" ></div> + <div class="clear"></div> + <div class="clear"></div> + <div id="twitter"> + <a href="https://twitter.com/ASFMavenProject" class="twitter-follow-button" data-show-count="false" data-align="left" data-size="medium" data-show-screen-name="true" data-lang="en">Follow ASFMavenProject</a> + <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> + </div> + <div class="clear"></div> + <div class="clear"></div> + <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a> + </div> + </div> + </div> + <div id="bodyColumn" class="span10" > +<div class="section"> +<h2><a name="Resource_Transformers"></a>Resource Transformers</h2> +<p>Aggregating classes/resources from several artifacts into one uber JAR is straight forward as long as there is no overlap. Otherwise, some kind of logic to merge resources from several JARs is required. This is where resource transformers kick in.</p> +<table border="1" class="table table-striped"><caption>Transformers in <tt>org.apache.maven.plugins.shade.resource</tt> +</caption> +<tr class="a"> +<td align="left"><a href="#ApacheLicenseResourceTransformer">ApacheLicenseResourceTransformer</a></td> +<td align="left">Prevents license duplication</td></tr> +<tr class="b"> +<td align="left"><a href="#ApacheNoticeResourceTransformer">ApacheNoticeResourceTransformer</a></td> +<td align="left">Prepares merged NOTICE</td></tr> +<tr class="a"> +<td align="left"><a href="#AppendingTransformer">AppendingTransformer</a></td> +<td align="left">Adds content to a resource</td></tr> +<tr class="b"> +<td align="left"><a href="#ComponentsXmlResourceTransformer">ComponentsXmlResourceTransformer</a></td> +<td align="left">Aggregates Plexus <tt>components.xml</tt></td></tr> +<tr class="a"> +<td align="left"><a href="#DontIncludeResourceTransformer">DontIncludeResourceTransformer</a></td> +<td align="left">Prevents inclusion of matching resources</td></tr> +<tr class="b"> +<td align="left"><a href="#GroovyResourceTransformer">GroovyResourceTransformer</a></td> +<td align="left">Merges Apache Groovy extends modules</td></tr> +<tr class="a"> +<td align="left"><a href="#IncludeResourceTransformer">IncludeResourceTransformer</a></td> +<td align="left">Adds files from the project</td></tr> +<tr class="b"> +<td align="left"><a href="#ManifestResourceTransformer">ManifestResourceTransformer</a></td> +<td align="left">Sets entries in the <tt>MANIFEST</tt></td></tr> +<tr class="a"> +<td align="left"><a href="#PluginXmlResourceTransformer">PluginXmlResourceTransformer</a></td> +<td align="left">Aggregates Mavens <tt>plugin.xml</tt></td></tr> +<tr class="b"> +<td align="left"><a href="#ResourceBundleAppendingTransformer">ResourceBundleAppendingTransformer</a></td> +<td align="left">Merges ResourceBundles</td></tr> +<tr class="a"> +<td align="left"><a href="#ServicesResourceTransformer">ServicesResourceTransformer</a></td> +<td align="left">Relocated class names in <tt>META-INF/services</tt> resources and merges them.</td></tr> +<tr class="b"> +<td align="left"><a href="#XmlAppendingTransformer">XmlAppendingTransformer</a></td> +<td align="left">Adds XML content to an XML resource</td></tr></table> +<table border="1" class="table table-striped"><caption>Transformers in <tt>org.apache.maven.plugins.shade.resource.properties</tt> (available since 3.2.2)</caption> +<tr class="a"> +<td align="left"><a href="#PropertiesTransformer">PropertiesTransformer</a></td> +<td align="left">Merges properties files owning an ordinal to solve conflicts</td></tr> +<tr class="b"> +<td align="left"><a href="#OpenWebBeansPropertiesTransformer">OpenWebBeansPropertiesTransformer</a></td> +<td align="left">Merges Apache OpenWebBeans configuration files</td></tr> +<tr class="a"> +<td align="left"><a href="#MicroprofileConfigTransformer">MicroprofileConfigTransformer</a></td> +<td align="left">Merges conflicting Microprofile Config properties based on an ordinal</td></tr></table> +<div class="section"> +<h3><a name="Merging_Plexus_Component_Descriptors_with_the_ComponentsXmlResourceTransformer"></a>Merging Plexus Component Descriptors with the <a name="ComponentsXmlResourceTransformer">ComponentsXmlResourceTransformer</a></h3> +<p>JARs for components targeting the Plexus IoC container contain a <tt>META-INF/plexus/components.xml</tt> entry that declares the component and its requirements. If the uber JAR aggregates multiple Plexus components, a <tt>ComponentsXmlResourceTransformer</tt> needs to be used to merge the XML descriptors:</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div> +<p>Since plugin version 1.3, this resource transformer will also update the descriptor to account for relocation of component interfaces/implementations (if any).</p></div> +<div class="section"> +<h3><a name="Relocate_classes_of_the_Maven_Plugin_Descriptor_with_the_PluginXmlResourceTransformer"></a>Relocate classes of the Maven Plugin Descriptor with the <a name="PluginXmlResourceTransformer">PluginXmlResourceTransformer</a></h3> +<p>With <a class="externalLink" href="http://maven.apache.org/plugin-tools/index.html">Plugin Tools 3.0</a> annotations have been introduced. Now references to classes are no longer classnames as String, but the actual Class reference. When you wanted to relocate classes, you had to maintain the <tt>META-INF/maven/plugin.xml</tt> by hand, but now this can be done with the <tt>PluginXmlResourceTransformer</tt> </p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer"/> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h3><a name="Concatenating_Service_Entries_with_the_ServicesResourceTransformer"></a>Concatenating Service Entries with the <a name="ServicesResourceTransformer">ServicesResourceTransformer</a></h3> +<p>JAR files providing implementations of some interfaces often ship with a <tt>META-INF/services/</tt> directory that maps interfaces to their implementation classes for lookup by the service locator. To relocate the class names of these implementation classes, and to merge multiple implementations of the same interface into one service entry, the <tt>ServicesResourceTransformer</tt> can be used:</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h3><a name="Merging_Content_of_Specific_Files_with_AppendingTransformer.2C_XmlAppendingTransformer_and_ResourceBundleAppendingTransformer"></a>Merging Content of Specific Files with <a name="AppendingTransformer">AppendingTransformer</a>, XmlAppendingTransformer and ResourceBundleAppendingTransformer</h3> +<p>Some jars contain additional resources (such as properties files) that have the same file name. To avoid overwriting, you can opt to merge them by appending their content into one file. One good example for this is when aggregating both the spring-context and plexus-spring jars. Both of them have the <tt>META-INF/spring.handlers</tt> file which is used by Spring to handle XML schema namespaces. You can merge the contents of all the files with that specific name using the <tt>AppendingTransformer</tt> as shown below:</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>META-INF/spring.handlers</resource> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>META-INF/spring.schemas</resource> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div> +<p>For XML files, you can use the <tt><a name="XmlAppendingTransformer">XmlAppendingTransformer</a></tt> instead:</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> + <resource>META-INF/magic.xml</resource> + <!-- Add this to enable loading of DTDs + <ignoreDtd>false</ignoreDtd> + --> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div> +<p>Since plugin version 1.3.1, the <tt>XmlAppendingTransformer</tt> will by default not load DTDs, thereby avoiding network access. The potential downside of this mode is that external entities cannot be resolved which could fail the transformation, e.g. when using the Crimson XML parser as used in some JRE 1.4. If the transformed resource uses external entities, DTD resolution can either be turned back on or a plugin dependency on <tt>xerces:xercesImpl:2.9.1</tt> is added to the POM.</p> +<p>For ResourceBundles properties files, you can use the <tt><a name="ResourceBundleAppendingTransformer">ResourceBundleAppendingTransformer</a></tt> instead, which will respect all available Locales as well:</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ResourceBundleAppendingTransformer"> + <!-- the base name of the resource bundle, a fully qualified class name --> + <basename>path/to/Messages</basename> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h3><a name="Excluding_Resources_with_the_DontIncludeResourceTransformer"></a>Excluding Resources with the <a name="DontIncludeResourceTransformer">DontIncludeResourceTransformer</a></h3> +<p>The <tt>DontIncludeResourceTransformer</tt> allows resources to be excluded when their name ends in a given value.</p> +<p>For example, the following sample excludes all resources ending in <tt>.txt</tt>.</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> + <resource>.txt</resource> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div> +<p>Since maven-shade-plugin-3.0 it is also possible to give a list of resources which should not be included, like: </p> +<div class="source"><pre class="prettyprint linenums"><transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> + <resources> + <resource>.txt</resource> + <resource>READ.me</resource> + </resources> +</transformer></pre></div></div> +<div class="section"> +<h3><a name="Adding_New_Resources_with_the_IncludeResourceTransformer"></a>Adding New Resources with the <a name="IncludeResourceTransformer">IncludeResourceTransformer</a></h3> +<p>The <tt>IncludeResourceTransformer</tt> allows project files to be included in the package under a given name.</p> +<p>For example, the following sample includes <tt>README.txt</tt> in the package as <tt>README</tt> in the <tt>META-INF</tt> directory.</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> + <resource>META-INF/README</resource> + <file>README.txt</file> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h3><a name="Setting_Manifest_Entries_with_the_ManifestResourceTransformer"></a>Setting Manifest Entries with the <a name="ManifestResourceTransformer">ManifestResourceTransformer</a></h3> +<p>The <tt>ManifestResourceTransformer</tt> allows existing entries in the <tt>MANIFEST</tt> to be replaced and new entries added. </p> +<p>For example, the following sample sets</p> +<ul> +<li>the <tt>Main-Class</tt> entry to the value of the <tt>app.main.class</tt> property,</li> +<li>the <tt>X-Compile-Source-JDK</tt> entry to the value of the <tt>maven.compile.source</tt> property and</li> +<li>the <tt>X-Compile-Target-JDK</tt> entry to the value of the <tt>maven.compile.target</tt> property.</li></ul> +<p>By default the <tt>ManifestResourceTransformer</tt> will relocate the following attributes:</p> +<ul> +<li>Export-Package</li> +<li>Import-Package</li> +<li>Provide-Capability</li> +<li>Require-Capability</li></ul> +<p>With <tt>additionalAttributes</tt> you can specify the attributes that need to be relocated too.</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Main-Class>${app.main.class}</Main-Class> + <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK> + <X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK> + </manifestEntries> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h3><a name="Licensing"></a>Licensing</h3> +<div class="section"> +<h4><a name="Preventing_License_Duplication_with_the_ApacheLicenseResourceTransformer"></a>Preventing License Duplication with the <a name="ApacheLicenseResourceTransformer">ApacheLicenseResourceTransformer</a></h4> +<p>Some open source producers (including the <a class="externalLink" href="https://www.apache.org"> Apache Software Foundation</a>) include a copy of their license in the META-INF directory. These are conventionally named either <tt>LICENSE</tt>,<tt>LICENSE.txt</tt> or <tt>LICENSE.md</tt>. When merging these dependencies, adding these resources may cause confusion. The <tt>ApacheLicenseResourceTransformer</tt> ensures that duplicate licenses (named according to this convention) are not merged. </p> +<p>For example, the following prevents the license from a <tt>commons-collections</tt> dependency being merged in</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h4><a name="Aggregating_Notices_with_the_ApacheNoticeResourceTransformer"></a>Aggregating Notices with the <a name="ApacheNoticeResourceTransformer">ApacheNoticeResourceTransformer</a></h4> +<p>Some licenses (including the <a class="externalLink" href="https://www.apache.org/licenses/LICENSE-2.0.html"> Apache License, Version 2</a>) require that notices are preserved by downstream distributors. <tt>ApacheNoticeResourceTransformer</tt> automates the assembly of an appropriate <tt>NOTICE</tt>.</p> +<p>For example, to simply merge in dependent notices:</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer"> + <addHeader>false</addHeader> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h4><a name="Aggregating_Apache_Groovy_extension_modules_descriptors_with_the_GroovyResourceTransformer"></a>Aggregating Apache Groovy extension modules descriptors with the <a name="GroovyResourceTransformer">GroovyResourceTransformer</a></h4> +<p>The Apache Groovy language provides extension modules located at <tt>META-INF/services/org.codehaus.groovy.runtime.ExtensionModule</tt>, these modules use the property file format. <tt>GroovyResourceTransformer</tt> automates the assembly of Groovy extension modules <tt>NOTICE</tt>.</p> +<p>For example, to simply merge the extension modules of several jars:</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.GroovyResourceTransformer"> + <extModuleName>the-aggregated-module</extModuleName> + <extModuleVersion>1.0.0</extModuleVersion> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div></div> +<div class="section"> +<h3><a name="Merging_properties_files_with_PropertiesTransformer"></a>Merging properties files with <a name="PropertiesTransformer">PropertiesTransformer</a></h3> +<p>The <tt>PropertiesTransformer</tt> allows a set of properties files to be merged and to resolve conflicts based on an ordinal giving the priority of each file. An optional <tt>alreadyMergedKey</tt> enables to have a boolean flag in the file which, if set to true, request to use the file as it as the result of the merge. If two files are considered complete in the merge process then the shade will fail.</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.properties.PropertiesTransformer"> + <!-- required configuration --> + <resource>configuration/application.properties</resource> + <ordinalKey>ordinal</ordinalKey> + <!-- optional configuration --> + <alreadyMergedKey>already_merged</alreadyMergedKey> + <defaultOrdinal>0</defaultOrdinal> + <reverseOrder>false</reverseOrder> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h3><a name="Merging_Apache_OpenWebBeans_configuration_with_OpenWebBeansPropertiesTransformer"></a>Merging Apache OpenWebBeans configuration with <a name="OpenWebBeansPropertiesTransformer">OpenWebBeansPropertiesTransformer</a></h3> +<p><tt>OpenWebBeansPropertiesTransformer</tt> preconfigure a <tt>PropertiesTransformer</tt> for Apache OpenWebBeans configuration files.</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.properties.OpenWebBeansPropertiesTransformer" /> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div> +<div class="section"> +<h3><a name="Merging_Microprofile_Config_properties_with_MicroprofileConfigTransformer"></a>Merging Microprofile Config properties with <a name="MicroprofileConfigTransformer">MicroprofileConfigTransformer</a></h3> +<p><tt>MicroprofileConfigTransformer</tt> preconfigure a <tt>PropertiesTransformer</tt> for Microprofile Config. The only required configuration is the ordinal. The <tt>alreadyMergedKey</tt> is supported but is not defined by the specification.</p> +<div class="source"><pre class="prettyprint linenums"><project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.properties.MicroprofileConfigTransformer"> + <resource>configuration/app.properties</resource> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project></pre></div></div></div> + </div> + </div> + </div> + <hr/> + <footer> + <div class="container-fluid"> + <div class="row-fluid"> + <p>Copyright ©2002–2022 +<a href="https://www.apache.org/">The Apache Software Foundation</a>. +All rights reserved.</p> + </div> + </div> + </footer> + </body> </html> \ No newline at end of file