-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
o Splitted examples into multiple small documents
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@764546 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
8 changed files
with
457 additions
and
438 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
------ | ||
Attaching the Shaded Artifact | ||
------ | ||
Mauro Talevi | ||
------ | ||
2008-07-21 | ||
------ | ||
|
||
~~ Licensed to the Apache Software Foundation (ASF) under one | ||
~~ or more contributor license agreements. See the NOTICE file | ||
~~ distributed with this work for additional information | ||
~~ regarding copyright ownership. The ASF licenses this file | ||
~~ to you under the Apache License, Version 2.0 (the | ||
~~ "License"); you may not use this file except in compliance | ||
~~ with the License. You may obtain a copy of the License at | ||
~~ | ||
~~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~~ | ||
~~ Unless required by applicable law or agreed to in writing, | ||
~~ software distributed under the License is distributed on an | ||
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~~ KIND, either express or implied. See the License for the | ||
~~ specific language governing permissions and limitations | ||
~~ under the License. | ||
|
||
Attaching the Shaded Artifact | ||
|
||
By default, the plugin will replace the project's main artifact with the shaded artifact. If both the original and | ||
the shaded artifact should be installed/deployed to the repository, one can configure the plugin to attach the | ||
shaded artifact as a secondary artifact: | ||
|
||
+----- | ||
<project> | ||
... | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<shadedArtifactAttached>true</shadedArtifactAttached> | ||
<shadedClassifierName>jackofall</shadedClassifierName> <!-- Any name that makes sense --> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
</project> | ||
+----- | ||
|
||
The shaded artifact is distinguished from the main artifact by means of the additional classifier. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
------ | ||
Relocating Classes | ||
------ | ||
Mauro Talevi | ||
------ | ||
2008-07-21 | ||
------ | ||
|
||
~~ Licensed to the Apache Software Foundation (ASF) under one | ||
~~ or more contributor license agreements. See the NOTICE file | ||
~~ distributed with this work for additional information | ||
~~ regarding copyright ownership. The ASF licenses this file | ||
~~ to you under the Apache License, Version 2.0 (the | ||
~~ "License"); you may not use this file except in compliance | ||
~~ with the License. You may obtain a copy of the License at | ||
~~ | ||
~~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~~ | ||
~~ Unless required by applicable law or agreed to in writing, | ||
~~ software distributed under the License is distributed on an | ||
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~~ KIND, either express or implied. See the License for the | ||
~~ specific language governing permissions and limitations | ||
~~ under the License. | ||
|
||
Relocating Classes | ||
|
||
If the uber JAR is reused as a dependency of some other project, directly including classes from the artifact's | ||
dependencies in the uber JAR can cause class loading conflicts due to duplicate classes on the class path. To | ||
address this issue, one can relocate the classes which get included in the shaded artifact in order to create a | ||
private copy of their bytecode: | ||
|
||
+----- | ||
<project> | ||
... | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<relocations> | ||
<relocation> | ||
<pattern>org.codehaus.plexus.util</pattern> | ||
<shadedPattern>org.shaded.plexus.util</shadedPattern> | ||
<excludes> | ||
<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude> | ||
<exclude>org.codehaus.plexus.util.xml.pull.*</exclude> | ||
</excludes> | ||
</relocation> | ||
</relocations> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
</project> | ||
+----- | ||
|
||
This instructs the plugin to move classes from the package <<<org.codehaus.plexus.util>>> and its subpackages | ||
into the package <<<org.shaded.plexus.util>>> by moving the corresponding JAR file entries and rewritting the | ||
affected bytecode. The class <<<Xpp3Dom>>> and some others will remain in their original package. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
------ | ||
Executable JAR | ||
------ | ||
Mauro Talevi | ||
------ | ||
2008-07-21 | ||
------ | ||
|
||
~~ Licensed to the Apache Software Foundation (ASF) under one | ||
~~ or more contributor license agreements. See the NOTICE file | ||
~~ distributed with this work for additional information | ||
~~ regarding copyright ownership. The ASF licenses this file | ||
~~ to you under the Apache License, Version 2.0 (the | ||
~~ "License"); you may not use this file except in compliance | ||
~~ with the License. You may obtain a copy of the License at | ||
~~ | ||
~~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~~ | ||
~~ Unless required by applicable law or agreed to in writing, | ||
~~ software distributed under the License is distributed on an | ||
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~~ KIND, either express or implied. See the License for the | ||
~~ specific language governing permissions and limitations | ||
~~ under the License. | ||
|
||
Executable JAR | ||
|
||
To create an executable uber JAR, one simply needs to set the main class that serves as the application entry point: | ||
|
||
+----- | ||
<project> | ||
... | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.sonatype.haven.HavenCli</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
</project> | ||
+----- | ||
|
||
This snippet configures a special resource transformer which sets the <<<Main-Class>>> entry in the <<<MANIFEST.MF>>> | ||
of the shaded JAR. Other entries can be added to the <<<MANIFEST.MF>>> as well via key-value pairs in the | ||
<<<\<manifestEntries\>>>> section: | ||
|
||
+----- | ||
<project> | ||
... | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<manifestEntries> | ||
<Main-Class>org.sonatype.haven.ExodusCli</Main-Class> | ||
<Build-Number>123</Build-Number> | ||
</manifestEntries> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
</project> | ||
+----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
------ | ||
Selecting Contents for Uber JAR | ||
------ | ||
Mauro Talevi | ||
------ | ||
2008-07-21 | ||
------ | ||
|
||
~~ Licensed to the Apache Software Foundation (ASF) under one | ||
~~ or more contributor license agreements. See the NOTICE file | ||
~~ distributed with this work for additional information | ||
~~ regarding copyright ownership. The ASF licenses this file | ||
~~ to you under the Apache License, Version 2.0 (the | ||
~~ "License"); you may not use this file except in compliance | ||
~~ with the License. You may obtain a copy of the License at | ||
~~ | ||
~~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~~ | ||
~~ Unless required by applicable law or agreed to in writing, | ||
~~ software distributed under the License is distributed on an | ||
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~~ KIND, either express or implied. See the License for the | ||
~~ specific language governing permissions and limitations | ||
~~ under the License. | ||
|
||
Selecting Contents for Uber JAR | ||
|
||
The POM snippet below shows how to control which project dependencies should be included/excluded in the uber JAR: | ||
|
||
+----- | ||
<project> | ||
... | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<artifactSet> | ||
<excludes> | ||
<exclude>classworlds:classworlds</exclude> | ||
<exclude>junit:junit</exclude> | ||
<exclude>jmock:jmock</exclude> | ||
<exclude>xml-apis:xml-apis</exclude> | ||
</excludes> | ||
</artifactSet> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
</project> | ||
+----- | ||
|
||
Of course, <<<\<includes\>>>> can be used as well to specify a white list of artifacts. Artifacts are denoted by a | ||
composite idenitifer of the form <groupId>:<artifactId>[:<classifier>]. | ||
|
||
For fine-grained control of which classes from the selected dependencies are included, artifact filters can be used: | ||
|
||
+----- | ||
<project> | ||
... | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<filters> | ||
<filter> | ||
<artifact>junit:junit</artifact> | ||
<includes> | ||
<include>junit/framework/**</include> | ||
<include>org/junit/**</include> | ||
</includes> | ||
<excludes> | ||
<exclude>org/junit/experimental/**</exclude> | ||
<exclude>org/junit/runners/**</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
</project> | ||
+----- | ||
|
||
Here, Ant-like patterns are used to specify that from the dependency <<<junit:junit>>> only certain classes/resources | ||
should be included in the uber JAR. |
Oops, something went wrong.