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
Fields Modifier and Type Field Description protected org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver
artifactResolver
Artifact resolver, needed to download source jars for inclusion in classpath.private ArtifactSet
artifactSet
Artifacts to include/exclude from the final artifact.private boolean
createDependencyReducedPom
Flag whether to generate a simplified POM for the shaded artifact.private boolean
createSourcesJar
When true, it will attempt to create a sources jar as wellprivate boolean
createTestSourcesJar
When true, it will attempt to create a test sources jar.private org.apache.maven.shared.dependency.graph.DependencyGraphBuilder
dependencyGraphBuilder
The dependency graph builder to use.private java.io.File
dependencyReducedPomLocation
Where to put the dependency reduced pom.private ArchiveFilter[]
filters
Archive Filters to be used.private java.lang.String
finalName
The name of the shaded artifactId.private boolean
generateUniqueDependencyReducedPom
Create a dependency-reduced POM in ${basedir}/drp-UNIQUE.pom.private boolean
keepDependenciesWithProvidedScope
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
localRepository
Local maven repository.private boolean
minimizeJar
When true, dependencies will be stripped down on the class level to only the transitive hull required for the artifact.private java.io.File
outputDirectory
The destination directory for the shaded artifact.private java.io.File
outputFile
The path to the output file for the shaded artifact.private org.codehaus.plexus.PlexusContainer
plexusContainer
private org.apache.maven.project.MavenProject
project
The current Maven project.private org.apache.maven.project.ProjectBuilder
projectBuilder
ProjectBuilder, needed to create projects from the artifacts.private org.apache.maven.project.MavenProjectHelper
projectHelper
private boolean
promoteTransitiveDependencies
When true, transitive deps of removed dependencies are promoted to direct dependencies.private PackageRelocation[]
relocations
Packages to be relocated.protected java.util.List<org.apache.maven.artifact.repository.ArtifactRepository>
remoteArtifactRepositories
Remote repositories which will be searched for source attachments.private org.apache.maven.execution.MavenSession
session
The current Maven session.private boolean
shadedArtifactAttached
Defines whether the shaded artifact should be attached as classifier to the original artifact.private java.lang.String
shadedArtifactId
The name of the shaded artifactId.private java.lang.String
shadedClassifierName
The name of the classifier used in case the shaded artifact is attached.private java.lang.String
shadedGroupFilter
If specified, this will include only artifacts which have groupIds which start with this.private Shader
shader
private java.lang.String
shaderHint
You can pass here the roleHint about your own Shader implementation plexus component.private boolean
shadeSourcesContent
When true, it will attempt to shade the contents of the java source files when creating the sources jar.private boolean
shadeTestJar
When true, creates a shaded test-jar artifact as well.private ResourceTransformer[]
transformers
Resource transformers to be used.private boolean
useBaseVersion
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.
-
Constructor Summary
Constructors Constructor Description ShadeMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addSystemScopedDependencyFromNonInterpolatedPom(java.util.List<org.apache.maven.model.Dependency> dependencies, java.util.List<org.apache.maven.model.Dependency> originalDependencies)
void
contextualize(org.codehaus.plexus.context.Context context)
private void
copyFiles(java.io.File source, java.io.File target)
private org.apache.maven.model.Dependency
createDependency(org.apache.maven.artifact.Artifact artifact)
private void
createDependencyReducedPom(java.util.Set<java.lang.String> artifactsToRemove)
private void
createErrorOutput()
private ShadeRequest
createShadeSourcesRequest(java.util.Set<java.io.File> testArtifacts, java.io.File testJar, java.util.List<Filter> filters, java.util.List<Relocator> relocators, java.util.List<ResourceTransformer> resourceTransformers)
void
execute()
private java.util.List<Filter>
getFilters()
private java.lang.String
getId(java.lang.String groupId, java.lang.String artifactId, java.lang.String type, java.lang.String classifier)
private java.lang.String
getId(org.apache.maven.artifact.Artifact artifact)
private java.lang.String
getId(org.apache.maven.model.Dependency dependency)
private java.util.List<Relocator>
getRelocators()
private java.util.List<ResourceTransformer>
getResourceTransformers()
private boolean
invalidMainArtifact()
private void
processArtifactSelectors(java.util.Set<java.io.File> artifacts, java.util.Set<java.lang.String> artifactIds, java.util.Set<java.io.File> sourceArtifacts, java.util.Set<java.io.File> testArtifacts, java.util.Set<java.io.File> testSourceArtifacts, ArtifactSelector artifactSelector)
private void
removeSystemScopedDependencies(java.util.Set<java.lang.String> artifactsToRemove, java.util.List<org.apache.maven.model.Dependency> originalDependencies)
private void
replaceFile(java.io.File oldFile, java.io.File newFile)
private java.io.File
resolveArtifactForClassifier(org.apache.maven.artifact.Artifact artifact, java.lang.String classifier)
private void
rewriteDependencyReducedPomIfWeHaveReduction(java.util.List<org.apache.maven.model.Dependency> dependencies, boolean modified, java.util.List<org.apache.maven.model.Dependency> transitiveDeps, org.apache.maven.model.Model model)
private void
setupHintedShader()
private java.io.File
shadedArtifactFile(java.lang.String classifier)
private java.io.File
shadedArtifactFileWithClassifier()
private java.io.File
shadedArtifactFileWithClassifier(java.lang.String classifier)
private java.io.File
shadedSourceArtifactFileWithClassifier()
private java.io.File
shadedSourcesArtifactFile()
private java.io.File
shadedTestArtifactFile()
private java.io.File
shadedTestArtifactFileWithClassifier()
private java.io.File
shadedTestSourceArtifactFileWithClassifier()
private java.io.File
shadedTestSourcesArtifactFile()
private ShadeRequest
shadeRequest(java.util.Set<java.io.File> artifacts, java.io.File outputJar, java.util.List<Filter> filters, java.util.List<Relocator> relocators, java.util.List<ResourceTransformer> resourceTransformers)
boolean
updateExcludesInDeps(org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.model.Dependency> dependencies, java.util.List<org.apache.maven.model.Dependency> transitiveDeps)
-
-
-
Field Detail
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
The current Maven session.
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
The current Maven project.
-
projectHelper
@Component private org.apache.maven.project.MavenProjectHelper projectHelper
-
shader
@Component(hint="default", role=Shader.class) private Shader shader
-
dependencyGraphBuilder
@Component private org.apache.maven.shared.dependency.graph.DependencyGraphBuilder dependencyGraphBuilder
The dependency graph builder to use.
-
projectBuilder
@Component private org.apache.maven.project.ProjectBuilder projectBuilder
ProjectBuilder, needed to create projects from the artifacts.
-
remoteArtifactRepositories
@Parameter(readonly=true, required=true, defaultValue="${project.remoteArtifactRepositories}") protected java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories
Remote repositories which will be searched for source attachments.
-
localRepository
@Parameter(readonly=true, required=true, defaultValue="${localRepository}") protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
Local maven repository.
-
artifactResolver
@Component protected org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolver
Artifact resolver, needed to download source jars for inclusion in classpath.
-
artifactSet
@Parameter private ArtifactSet 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
@Parameter private PackageRelocation[] 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
@Parameter private ResourceTransformer[] transformers
Resource transformers to be used. Please see the "Examples" section for more information on available transformers and their configuration.
-
filters
@Parameter private ArchiveFilter[] 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
@Parameter(defaultValue="${project.build.directory}") private java.io.File outputDirectory
The destination directory for the shaded artifact.
-
finalName
@Parameter private java.lang.String 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
@Parameter(defaultValue="${project.artifactId}") private java.lang.String 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
@Parameter private java.lang.String shadedGroupFilter
If specified, this will include only artifacts which have groupIds which start with this.
-
shadedArtifactAttached
@Parameter private boolean shadedArtifactAttached
Defines 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 createDependencyReducedPom
Flag 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 java.io.File dependencyReducedPomLocation
Where 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 generateUniqueDependencyReducedPom
Create 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 keepDependenciesWithProvidedScope
When true, dependencies are kept in the pom but with scope 'provided'; when false, the dependency is removed.
-
promoteTransitiveDependencies
@Parameter private boolean promoteTransitiveDependencies
When 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
@Parameter(defaultValue="shaded") private java.lang.String shadedClassifierName
The name of the classifier used in case the shaded artifact is attached.
-
createSourcesJar
@Parameter private boolean createSourcesJar
When true, it will attempt to create a sources jar as well
-
createTestSourcesJar
@Parameter private boolean createTestSourcesJar
When true, it will attempt to create a test sources jar.
-
shadeSourcesContent
@Parameter(property="shadeSourcesContent", defaultValue="false") private boolean shadeSourcesContent
When 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 minimizeJar
When 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
@Parameter private java.io.File 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
@Parameter private java.lang.String shaderHint
You can pass here the roleHint about your own Shader implementation plexus component.- Since:
- 1.6
-
useBaseVersion
@Parameter(defaultValue="false") private boolean useBaseVersion
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. 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 shadeTestJar
When true, creates a shaded test-jar artifact as well.
-
plexusContainer
private org.codehaus.plexus.PlexusContainer plexusContainer
- Since:
- 1.6
-
-
Method Detail
-
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(java.util.Set<java.io.File> artifacts, java.io.File outputJar, java.util.List<Filter> filters, java.util.List<Relocator> relocators, java.util.List<ResourceTransformer> resourceTransformers)
-
createShadeSourcesRequest
private ShadeRequest createShadeSourcesRequest(java.util.Set<java.io.File> testArtifacts, java.io.File testJar, java.util.List<Filter> filters, java.util.List<Relocator> relocators, java.util.List<ResourceTransformer> resourceTransformers)
-
setupHintedShader
private void setupHintedShader() throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
processArtifactSelectors
private void processArtifactSelectors(java.util.Set<java.io.File> artifacts, java.util.Set<java.lang.String> artifactIds, java.util.Set<java.io.File> sourceArtifacts, java.util.Set<java.io.File> testArtifacts, java.util.Set<java.io.File> testSourceArtifacts, ArtifactSelector artifactSelector)
-
invalidMainArtifact
private boolean invalidMainArtifact()
-
replaceFile
private void replaceFile(java.io.File oldFile, java.io.File newFile) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
copyFiles
private void copyFiles(java.io.File source, java.io.File target) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveArtifactForClassifier
private java.io.File resolveArtifactForClassifier(org.apache.maven.artifact.Artifact artifact, java.lang.String classifier)
-
getRelocators
private java.util.List<Relocator> getRelocators()
-
getResourceTransformers
private java.util.List<ResourceTransformer> getResourceTransformers()
-
getFilters
private java.util.List<Filter> getFilters() throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
shadedArtifactFileWithClassifier
private java.io.File shadedArtifactFileWithClassifier()
-
shadedSourceArtifactFileWithClassifier
private java.io.File shadedSourceArtifactFileWithClassifier()
-
shadedTestSourceArtifactFileWithClassifier
private java.io.File shadedTestSourceArtifactFileWithClassifier()
-
shadedArtifactFileWithClassifier
private java.io.File shadedArtifactFileWithClassifier(java.lang.String classifier)
-
shadedTestArtifactFileWithClassifier
private java.io.File shadedTestArtifactFileWithClassifier()
-
shadedSourcesArtifactFile
private java.io.File shadedSourcesArtifactFile()
-
shadedTestSourcesArtifactFile
private java.io.File shadedTestSourcesArtifactFile()
-
shadedArtifactFile
private java.io.File shadedArtifactFile(java.lang.String classifier)
-
shadedTestArtifactFile
private java.io.File shadedTestArtifactFile()
-
createDependencyReducedPom
private void createDependencyReducedPom(java.util.Set<java.lang.String> artifactsToRemove) throws java.io.IOException, org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException, org.apache.maven.project.ProjectBuildingException
- Throws:
java.io.IOException
org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
org.apache.maven.project.ProjectBuildingException
-
rewriteDependencyReducedPomIfWeHaveReduction
private void rewriteDependencyReducedPomIfWeHaveReduction(java.util.List<org.apache.maven.model.Dependency> dependencies, boolean modified, java.util.List<org.apache.maven.model.Dependency> transitiveDeps, org.apache.maven.model.Model model) throws java.io.IOException, org.apache.maven.project.ProjectBuildingException, org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
- Throws:
java.io.IOException
org.apache.maven.project.ProjectBuildingException
org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
-
removeSystemScopedDependencies
private void removeSystemScopedDependencies(java.util.Set<java.lang.String> artifactsToRemove, java.util.List<org.apache.maven.model.Dependency> originalDependencies)
-
addSystemScopedDependencyFromNonInterpolatedPom
private void addSystemScopedDependencyFromNonInterpolatedPom(java.util.List<org.apache.maven.model.Dependency> dependencies, java.util.List<org.apache.maven.model.Dependency> originalDependencies)
-
createDependency
private org.apache.maven.model.Dependency createDependency(org.apache.maven.artifact.Artifact artifact)
-
getId
private java.lang.String getId(org.apache.maven.artifact.Artifact artifact)
-
getId
private java.lang.String getId(org.apache.maven.model.Dependency dependency)
-
getId
private java.lang.String getId(java.lang.String groupId, java.lang.String artifactId, java.lang.String type, java.lang.String classifier)
-
updateExcludesInDeps
public boolean updateExcludesInDeps(org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.model.Dependency> dependencies, java.util.List<org.apache.maven.model.Dependency> transitiveDeps) throws org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
- Throws:
org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException
-
-