Class ShadeMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.shade.mojo.ShadeMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
,org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
@Mojo(name="shade",
defaultPhase=PACKAGE,
threadSafe=true,
requiresDependencyResolution=RUNTIME)
public class ShadeMojo
extends org.apache.maven.plugin.AbstractMojo
implements org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
Mojo that performs shading delegating to the Shader component.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver
Artifact resolver, needed to download source jars for inclusion in classpath.private ArtifactSet
Artifacts to include/exclude from the final artifact.private boolean
Flag whether to generate a simplified POM for the shaded artifact.private boolean
When true, it will attempt to create a sources jar as wellprivate boolean
When true, it will attempt to create a test sources jar.private org.apache.maven.shared.dependency.graph.DependencyGraphBuilder
The dependency graph builder to use.private File
Where to put the dependency reduced pom.private ArchiveFilter[]
Archive Filters to be used.private String
The name of the shaded artifactId.private boolean
Create a dependency-reduced POM in ${basedir}/drp-UNIQUE.pom.private boolean
When true, dependencies are kept in the pom but with scope 'provided'; when false, the dependency is removed.protected org.apache.maven.artifact.repository.ArtifactRepository
Local maven repository.private boolean
When true, dependencies will be stripped down on the class level to only the transitive hull required for the artifact.private File
The destination directory for the shaded artifact.private File
The path to the output file for the shaded artifact.private org.codehaus.plexus.PlexusContainer
private org.apache.maven.project.MavenProject
The current Maven project.private org.apache.maven.project.ProjectBuilder
ProjectBuilder, needed to create projects from the artifacts.private org.apache.maven.project.MavenProjectHelper
private boolean
When true, transitive deps of removed dependencies are promoted to direct dependencies.private PackageRelocation[]
Packages to be relocated.protected List<org.apache.maven.artifact.repository.ArtifactRepository>
Remote repositories which will be searched for source attachments.private org.apache.maven.execution.MavenSession
The current Maven session.private boolean
Defines whether the shaded artifact should be attached as classifier to the original artifact.private String
The name of the shaded artifactId.private String
The name of the classifier used in case the shaded artifact is attached.private String
If specified, this will include only artifacts which have groupIds which start with this.private Shader
private String
You can pass here the roleHint about your own Shader implementation plexus component.private boolean
When true, it will attempt to shade the contents of the java source files when creating the sources jar.private boolean
When true, creates a shaded test-jar artifact as well.private ResourceTransformer[]
Resource transformers to be used.private boolean
When true, the version of each dependency of the reduced pom will be based on the baseVersion of the original dependency instead of its resolved version.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addSystemScopedDependencyFromNonInterpolatedPom
(List<org.apache.maven.model.Dependency> dependencies, List<org.apache.maven.model.Dependency> originalDependencies) void
contextualize
(org.codehaus.plexus.context.Context context) private void
private org.apache.maven.model.Dependency
createDependency
(org.apache.maven.artifact.Artifact artifact) private void
createDependencyReducedPom
(Set<String> artifactsToRemove) private void
private ShadeRequest
createShadeSourcesRequest
(Set<File> testArtifacts, File testJar, List<Filter> filters, List<Relocator> relocators, List<ResourceTransformer> resourceTransformers) void
execute()
private String
private String
getId
(org.apache.maven.artifact.Artifact artifact) private String
getId
(org.apache.maven.model.Dependency dependency) private List<ResourceTransformer>
private boolean
private void
processArtifactSelectors
(Set<File> artifacts, Set<String> artifactIds, Set<File> sourceArtifacts, Set<File> testArtifacts, Set<File> testSourceArtifacts, ArtifactSelector artifactSelector) private void
removeSystemScopedDependencies
(Set<String> artifactsToRemove, List<org.apache.maven.model.Dependency> originalDependencies) private void
replaceFile
(File oldFile, File newFile) private File
resolveArtifactForClassifier
(org.apache.maven.artifact.Artifact artifact, String classifier) private void
rewriteDependencyReducedPomIfWeHaveReduction
(List<org.apache.maven.model.Dependency> dependencies, boolean modified, List<org.apache.maven.model.Dependency> transitiveDeps, org.apache.maven.model.Model model) private void
private File
shadedArtifactFile
(String classifier) private File
private File
shadedArtifactFileWithClassifier
(String classifier) private File
private File
private File
private File
private File
private File
private ShadeRequest
shadeRequest
(Set<File> artifacts, File outputJar, List<Filter> filters, List<Relocator> relocators, List<ResourceTransformer> resourceTransformers) boolean
updateExcludesInDeps
(org.apache.maven.project.MavenProject project, List<org.apache.maven.model.Dependency> dependencies, List<org.apache.maven.model.Dependency> transitiveDeps) Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession sessionThe current Maven session. -
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe current Maven project. -
projectHelper
@Component private org.apache.maven.project.MavenProjectHelper projectHelper -
shader
-
dependencyGraphBuilder
@Component private org.apache.maven.shared.dependency.graph.DependencyGraphBuilder dependencyGraphBuilderThe dependency graph builder to use. -
projectBuilder
@Component private org.apache.maven.project.ProjectBuilder projectBuilderProjectBuilder, needed to create projects from the artifacts. -
remoteArtifactRepositories
@Parameter(readonly=true, required=true, defaultValue="${project.remoteArtifactRepositories}") protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositoriesRemote repositories which will be searched for source attachments. -
localRepository
@Parameter(readonly=true, required=true, defaultValue="${localRepository}") protected org.apache.maven.artifact.repository.ArtifactRepository localRepositoryLocal maven repository. -
artifactResolver
@Component protected org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolverArtifact resolver, needed to download source jars for inclusion in classpath. -
artifactSet
Artifacts to include/exclude from the final artifact. Artifacts are denoted by composite identifiers of the general formgroupId:artifactId:type:classifier
. Since version 1.3, the wildcard characters '*' and '?' can be used within the sub parts of those composite identifiers to do pattern matching. For convenience, the syntaxgroupId
is equivalent togroupId:*:*:*
,groupId:artifactId
is equivalent togroupId:artifactId:*:*
andgroupId:artifactId:classifier
is equivalent togroupId:artifactId:*:classifier
. For example:<artifactSet> <includes> <include>org.apache.maven:*</include> </includes> <excludes> <exclude>*:maven-core</exclude> </excludes> </artifactSet>
-
relocations
Packages to be relocated. For example:<relocations> <relocation> <pattern>org.apache</pattern> <shadedPattern>hidden.org.apache</shadedPattern> <includes> <include>org.apache.maven.*</include> </includes> <excludes> <exclude>org.apache.maven.Public*</exclude> </excludes> </relocation> </relocations>
Note: Support for includes exists only since version 1.4. -
transformers
Resource transformers to be used. Please see the "Examples" section for more information on available transformers and their configuration. -
filters
Archive Filters to be used. Allows you to specify an artifact in the form of a composite identifier as used byartifactSet
and a set of include/exclude file patterns for filtering which contents of the archive are added to the shaded jar. From a logical perspective, includes are processed before excludes, thus it's possible to use an include to collect a set of files from the archive then use excludes to further reduce the set. By default, all files are included and no files are excluded. If multiple filters apply to an artifact, the intersection of the matched files will be included in the final JAR. For example:<filters> <filter> <artifact>junit:junit</artifact> <includes> <include>org/junit/**</include> </includes> <excludes> <exclude>org/junit/experimental/**</exclude> </excludes> </filter> </filters>
-
outputDirectory
The destination directory for the shaded artifact. -
finalName
The name of the shaded artifactId. If you like to change the name of the native artifact, you may use the <build><finalName> setting. If this is set to something different than <build><finalName>, no file replacement will be performed, even if shadedArtifactAttached is being used. -
shadedArtifactId
The name of the shaded artifactId. So you may want to use a different artifactId and keep the standard version. If the original artifactId was "foo" then the final artifact would be something like foo-1.0.jar. So if you change the artifactId you might have something like foo-special-1.0.jar. -
shadedGroupFilter
If specified, this will include only artifacts which have groupIds which start with this. -
shadedArtifactAttached
@Parameter private boolean shadedArtifactAttachedDefines whether the shaded artifact should be attached as classifier to the original artifact. If false, the shaded jar will be the main artifact of the project -
createDependencyReducedPom
@Parameter(defaultValue="true") private boolean createDependencyReducedPomFlag whether to generate a simplified POM for the shaded artifact. If set totrue
, dependencies that have been included into the uber JAR will be removed from the<dependencies>
section of the generated POM. The reduced POM will be nameddependency-reduced-pom.xml
and is stored into the same directory as the shaded artifact. Unless you also specify dependencyReducedPomLocation, the plugin will create a temporary file nameddependency-reduced-pom.xml
in the project basedir. -
dependencyReducedPomLocation
@Parameter(defaultValue="${basedir}/dependency-reduced-pom.xml") private File dependencyReducedPomLocationWhere to put the dependency reduced pom. Note: setting a value for this parameter with a directory other than ${basedir} will change the value of ${basedir} for all executions that come after the shade execution. This is often not what you want. This is considered an open issue with this plugin.- Since:
- 1.7
-
generateUniqueDependencyReducedPom
@Parameter(defaultValue="false") private boolean generateUniqueDependencyReducedPomCreate a dependency-reduced POM in ${basedir}/drp-UNIQUE.pom. This avoids build collisions of parallel builds without moving the dependency-reduced POM to a different directory. The property maven.shade.dependency-reduced-pom is set to the generated filename.- Since:
- 1.7.2
-
keepDependenciesWithProvidedScope
@Parameter private boolean keepDependenciesWithProvidedScopeWhen true, dependencies are kept in the pom but with scope 'provided'; when false, the dependency is removed. -
promoteTransitiveDependencies
@Parameter private boolean promoteTransitiveDependenciesWhen true, transitive deps of removed dependencies are promoted to direct dependencies. This should allow the drop in replacement of the removed deps with the new shaded jar and everything should still work. -
shadedClassifierName
The name of the classifier used in case the shaded artifact is attached. -
createSourcesJar
@Parameter private boolean createSourcesJarWhen true, it will attempt to create a sources jar as well -
createTestSourcesJar
@Parameter private boolean createTestSourcesJarWhen true, it will attempt to create a test sources jar. -
shadeSourcesContent
@Parameter(property="shadeSourcesContent", defaultValue="false") private boolean shadeSourcesContentWhen true, it will attempt to shade the contents of the java source files when creating the sources jar. When false, it will just relocate the java source files to the shaded paths, but will not modify the actual contents of the java source files. -
minimizeJar
@Parameter private boolean minimizeJarWhen true, dependencies will be stripped down on the class level to only the transitive hull required for the artifact. Note: Usage of this feature requires Java 1.5 or higher.- Since:
- 1.4
-
outputFile
The path to the output file for the shaded artifact. When this parameter is set, the created archive will neither replace the project's main artifact nor will it be attached. Hence, this parameter causes the parametersfinalName
,shadedArtifactAttached
,shadedClassifierName
andcreateDependencyReducedPom
to be ignored when used.- Since:
- 1.3
-
shaderHint
You can pass here the roleHint about your own Shader implementation plexus component.- Since:
- 1.6
-
useBaseVersion
@Parameter(defaultValue="false") private boolean useBaseVersionWhen true, the version of each dependency of the reduced pom will be based on the baseVersion of the original dependency instead of its resolved version. For example, if the original pom (transitively) depends on a:a:2.7-SNAPSHOT, if useBaseVersion is set to false, the reduced pom will depend on a:a:2.7-20130312.222222-12 whereas if useBaseVersion is set to true, the reduced pom will depend on a:a:2.7-SNAPSHOT- Since:
- 3.0
-
shadeTestJar
@Parameter(defaultValue="false") private boolean shadeTestJarWhen true, creates a shaded test-jar artifact as well. -
plexusContainer
private org.codehaus.plexus.PlexusContainer plexusContainer- Since:
- 1.6
-
-
Constructor Details
-
ShadeMojo
public ShadeMojo()
-
-
Method Details
-
contextualize
public void contextualize(org.codehaus.plexus.context.Context context) throws org.codehaus.plexus.context.ContextException - Specified by:
contextualize
in interfaceorg.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
- Throws:
org.codehaus.plexus.context.ContextException
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Specified by:
execute
in interfaceorg.apache.maven.plugin.Mojo
- Throws:
org.apache.maven.plugin.MojoExecutionException
- in case of an error.
-
createErrorOutput
private void createErrorOutput() -
shadeRequest
private ShadeRequest shadeRequest(Set<File> artifacts, File outputJar, List<Filter> filters, List<Relocator> relocators, List<ResourceTransformer> resourceTransformers) -
createShadeSourcesRequest
private ShadeRequest createShadeSourcesRequest(Set<File> testArtifacts, File testJar, List<Filter> filters, List<Relocator> relocators, List<ResourceTransformer> resourceTransformers) -
setupHintedShader
private void setupHintedShader() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
processArtifactSelectors
-
invalidMainArtifact
private boolean invalidMainArtifact() -
replaceFile
private void replaceFile(File oldFile, File newFile) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
copyFiles
- Throws:
IOException
-
resolveArtifactForClassifier
-
getRelocators
-
getResourceTransformers
-
getFilters
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
shadedArtifactFileWithClassifier
-
shadedSourceArtifactFileWithClassifier
-
shadedTestSourceArtifactFileWithClassifier
-
shadedArtifactFileWithClassifier
-
shadedTestArtifactFileWithClassifier
-
shadedSourcesArtifactFile
-
shadedTestSourcesArtifactFile
-
shadedArtifactFile
-
shadedTestArtifactFile
-
createDependencyReducedPom
private void createDependencyReducedPom(Set<String> artifactsToRemove) throws IOException, org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException, org.apache.maven.project.ProjectBuildingException - Throws:
IOException
org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
org.apache.maven.project.ProjectBuildingException
-
rewriteDependencyReducedPomIfWeHaveReduction
private void rewriteDependencyReducedPomIfWeHaveReduction(List<org.apache.maven.model.Dependency> dependencies, boolean modified, List<org.apache.maven.model.Dependency> transitiveDeps, org.apache.maven.model.Model model) throws IOException, org.apache.maven.project.ProjectBuildingException, org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException - Throws:
IOException
org.apache.maven.project.ProjectBuildingException
org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
-
removeSystemScopedDependencies
-
addSystemScopedDependencyFromNonInterpolatedPom
-
createDependency
private org.apache.maven.model.Dependency createDependency(org.apache.maven.artifact.Artifact artifact) -
getId
-
getId
-
getId
-
updateExcludesInDeps
public boolean updateExcludesInDeps(org.apache.maven.project.MavenProject project, List<org.apache.maven.model.Dependency> dependencies, List<org.apache.maven.model.Dependency> transitiveDeps) throws org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException - Throws:
org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
-