Class PurgeLocalRepositoryMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.dependency.PurgeLocalRepositoryMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="purge-local-repository", threadSafe=true, requiresProject=false) public class PurgeLocalRepositoryMojo extends org.apache.maven.plugin.AbstractMojoWhen run on a project, remove the project dependencies from the local repository, and optionally re-resolve them. Outside of a project, remove the manually given dependencies.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPurgeLocalRepositoryMojo.DirectDependencyFilterIncludes only direct project dependencies.private static classPurgeLocalRepositoryMojo.SnapshotsFilterIncludes only snapshot artifacts.
-
Field Summary
Fields Modifier and Type Field Description private booleanactTransitivelyWhether this mojo should act on all transitive dependencies.private static java.lang.StringARTIFACT_ID_FUZZINESSprivate org.apache.maven.artifact.handler.manager.ArtifactHandlerManagerartifactHandlerManagerArtifact handler manager.private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverartifactResolverThe artifact resolver used to re-resolve dependencies, if that option is enabled.private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverdependencyResolverThe dependency resolver.private java.lang.StringexcludeComma-separated list of groupId:artifactId entries, which should be used to exclude artifacts from deletion/refresh.private java.util.List<java.lang.String>excludesThe list of dependencies in the form of groupId:artifactId which should NOT be deleted/refreshed.private static java.lang.StringGROUP_ID_FUZZINESSprivate java.lang.StringincludeComma-separated list of groupId:artifactId entries, which should be used to include artifacts for deletion/refresh.private java.util.List<java.lang.String>includesThe list of dependencies in the form of groupId:artifactId which should BE deleted/refreshed.private org.apache.maven.artifact.repository.ArtifactRepositorylocalRepositoryThe local repository, from which to delete artifacts.private java.lang.StringmanualIncludeComma-separated list of groupId:artifactId entries, which should be used to manually include artifacts for deletion.private java.util.List<java.lang.String>manualIncludesThe list of dependencies in the form of groupId:artifactId which should BE deleted/purged from the local repository.private org.apache.maven.plugin.MojoExecutionmojoExecutionThis mojo execution, used to determine if it was launched from the lifecycle or the command-line.private org.apache.maven.project.MavenProjectprojectThe current Maven project.private java.util.List<org.apache.maven.project.MavenProject>reactorProjectsThe Maven projects in the reactor.private booleanreResolveWhether to re-resolve the artifacts once they have been deleted from the local repository.private java.lang.StringresolutionFuzzinessDetermines how liberally the plugin will delete an artifact from the local repository.private org.apache.maven.execution.MavenSessionsessionprivate booleanskipSkip plugin execution completely.private booleansnapshotsOnlyWhether to purge only snapshot artifacts.private booleanverboseWhether this plugin should output verbose messages.private static java.lang.StringVERSION_FUZZINESS
-
Constructor Summary
Constructors Constructor Description PurgeLocalRepositoryMojo(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolver, org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private org.apache.maven.shared.artifact.filter.resolve.TransformableFiltercreatePurgeArtifactsFilter(org.apache.maven.project.MavenProject theProject, java.util.List<org.apache.maven.model.Dependency> dependencies, java.util.Set<org.apache.maven.artifact.Artifact> purgedArtifacts)Create the includes exclude filter to use when resolving and purging dependencies Also excludes any "system" scope dependencies.voidexecute()private java.io.FilefindDeleteTarget(org.apache.maven.artifact.Artifact artifact)private java.lang.StringgavToPath(java.lang.String gav)Convert a groupId:artifactId:version to a file system path.private java.util.Set<org.apache.maven.artifact.Artifact>getFilteredResolvedArtifacts(org.apache.maven.project.MavenProject theProject, java.util.List<org.apache.maven.model.Dependency> dependencies, org.apache.maven.shared.artifact.filter.resolve.TransformableFilter filter)private java.lang.StringgetProjectKey(org.apache.maven.project.MavenProject project)booleanisSkip()private voidmanualPurge(java.util.List<java.lang.String> theIncludes)Purge/Delete artifacts from the local repository according to the given patterns.private java.util.List<java.lang.String>parseIncludes(java.lang.String theInclude)Convert comma separated list of includes to List object.private voidpurgeArtifacts(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> artifacts)private voidpurgeLocalRepository(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> purgedArtifacts)Purges the local repository for the dependencies in the given Maven project.private voidreResolveArtifacts(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> artifacts)voidsetSkip(boolean skip)private booleanshouldPurgeAllProjectsInReactor()Determines if all projects in the reactor should be purged from their dependencies.private java.lang.StringtoPatternExcludes(org.apache.maven.artifact.Artifact artifact)Returns a string that represents a pattern for an exclude filter for the given artifact.private voidverbose(java.lang.String message)
-
-
-
Field Detail
-
VERSION_FUZZINESS
private static final java.lang.String VERSION_FUZZINESS
- See Also:
- Constant Field Values
-
ARTIFACT_ID_FUZZINESS
private static final java.lang.String ARTIFACT_ID_FUZZINESS
- See Also:
- Constant Field Values
-
GROUP_ID_FUZZINESS
private static final java.lang.String GROUP_ID_FUZZINESS
- See Also:
- Constant Field Values
-
project
private final org.apache.maven.project.MavenProject project
The current Maven project.
-
session
private final org.apache.maven.execution.MavenSession session
-
artifactHandlerManager
private final org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
Artifact handler manager.
-
dependencyResolver
private final org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolver
The dependency resolver.
-
artifactResolver
private final org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolver
The artifact resolver used to re-resolve dependencies, if that option is enabled.
-
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) private java.util.List<org.apache.maven.project.MavenProject> reactorProjectsThe Maven projects in the reactor.
-
mojoExecution
@Parameter(defaultValue="${mojo}", required=true, readonly=true) private org.apache.maven.plugin.MojoExecution mojoExecutionThis mojo execution, used to determine if it was launched from the lifecycle or the command-line.
-
manualIncludes
@Parameter private java.util.List<java.lang.String> manualIncludes
The list of dependencies in the form of groupId:artifactId which should BE deleted/purged from the local repository. Note that using this parameter will deactivate the normal process for purging the current project dependency tree. If this parameter is used, only the included artifacts will be purged. The manualIncludes parameter should not be used in combination with the includes/excludes parameters.- Since:
- 2.6
-
manualInclude
@Parameter(property="manualInclude") private java.lang.String manualInclude
Comma-separated list of groupId:artifactId entries, which should be used to manually include artifacts for deletion. This is a command-line alternative to themanualIncludesparameter, since List parameters are not currently compatible with CLI specification.- Since:
- 2.6
-
includes
@Parameter private java.util.List<java.lang.String> includes
The list of dependencies in the form of groupId:artifactId which should BE deleted/refreshed.- Since:
- 2.6
-
include
@Parameter(property="include") private java.lang.String include
Comma-separated list of groupId:artifactId entries, which should be used to include artifacts for deletion/refresh. This is a command-line alternative to theincludesparameter, since List parameters are not currently compatible with CLI specification.- Since:
- 2.6
-
excludes
@Parameter private java.util.List<java.lang.String> excludes
The list of dependencies in the form of groupId:artifactId which should NOT be deleted/refreshed.
-
exclude
@Parameter(property="exclude") private java.lang.String exclude
Comma-separated list of groupId:artifactId entries, which should be used to exclude artifacts from deletion/refresh. This is a command-line alternative to theexcludesparameter, since List parameters are not currently compatible with CLI specification.
-
reResolve
@Parameter(property="reResolve", defaultValue="true") private boolean reResolveWhether to re-resolve the artifacts once they have been deleted from the local repository. If you are running this mojo from the command-line, you may want to disable this. By default, artifacts will be re-resolved.
-
localRepository
@Parameter(defaultValue="${localRepository}", readonly=true, required=true) private org.apache.maven.artifact.repository.ArtifactRepository localRepositoryThe local repository, from which to delete artifacts.
-
resolutionFuzziness
@Parameter(property="resolutionFuzziness", defaultValue="version") private java.lang.String resolutionFuzzinessDetermines how liberally the plugin will delete an artifact from the local repository. Values are:
- file - Eliminate only the artifact's file.
- version (default) - Eliminate all files associated with the version of the artifact.
- artifactId - Eliminate all files associated with the artifact's artifactId.
- groupId - Eliminate all files associated with the artifact's groupId.
-
actTransitively
@Parameter(property="actTransitively", defaultValue="true") private boolean actTransitivelyWhether this mojo should act on all transitive dependencies. Default value is true.
-
verbose
@Parameter(property="verbose", defaultValue="false") private boolean verboseWhether this plugin should output verbose messages. Default is false.
-
snapshotsOnly
@Parameter(property="snapshotsOnly", defaultValue="false") private boolean snapshotsOnlyWhether to purge only snapshot artifacts.- Since:
- 2.4
-
skip
@Parameter(property="skip", defaultValue="false") private boolean skipSkip plugin execution completely.- Since:
- 2.7
-
-
Constructor Detail
-
PurgeLocalRepositoryMojo
@Inject public PurgeLocalRepositoryMojo(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolver, org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolver)
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
shouldPurgeAllProjectsInReactor
private boolean shouldPurgeAllProjectsInReactor()
Determines if all projects in the reactor should be purged from their dependencies. When this goal is started on the command-line, it is always the case. When it is bound to a phase in the lifecycle, it is never the case.- Returns:
trueif all projects in the reactor should be purged,falseotherwise
-
purgeLocalRepository
private void purgeLocalRepository(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> purgedArtifacts) throws org.apache.maven.plugin.MojoFailureExceptionPurges the local repository for the dependencies in the given Maven project.- Parameters:
theProject- maven projectpurgedArtifacts- the artifacts that were already purged- Throws:
org.apache.maven.plugin.MojoFailureException- in case of errors during the purge
-
manualPurge
private void manualPurge(java.util.List<java.lang.String> theIncludes) throws org.apache.maven.plugin.MojoExecutionExceptionPurge/Delete artifacts from the local repository according to the given patterns.- Parameters:
theIncludes- the includes- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error
-
gavToPath
private java.lang.String gavToPath(java.lang.String gav)
Convert a groupId:artifactId:version to a file system path.- Parameters:
gav- the groupId:artifactId:version string- Returns:
- the corresponding path
-
createPurgeArtifactsFilter
private org.apache.maven.shared.artifact.filter.resolve.TransformableFilter createPurgeArtifactsFilter(org.apache.maven.project.MavenProject theProject, java.util.List<org.apache.maven.model.Dependency> dependencies, java.util.Set<org.apache.maven.artifact.Artifact> purgedArtifacts)Create the includes exclude filter to use when resolving and purging dependencies Also excludes any "system" scope dependencies.- Parameters:
theProject- the Maven projectdependencies- the dependencies to use as a reference if we're excluding transitive dependenciespurgedArtifacts- the artifacts already purged- Returns:
- the created filter
-
toPatternExcludes
private java.lang.String toPatternExcludes(org.apache.maven.artifact.Artifact artifact)
Returns a string that represents a pattern for an exclude filter for the given artifact.- Parameters:
artifact- artifact- Returns:
- string representation of a pattern for an exclude filter for the given artifact
-
parseIncludes
private java.util.List<java.lang.String> parseIncludes(java.lang.String theInclude)
Convert comma separated list of includes to List object.- Parameters:
theInclude- the list of includes- Returns:
- the includes list
-
getFilteredResolvedArtifacts
private java.util.Set<org.apache.maven.artifact.Artifact> getFilteredResolvedArtifacts(org.apache.maven.project.MavenProject theProject, java.util.List<org.apache.maven.model.Dependency> dependencies, org.apache.maven.shared.artifact.filter.resolve.TransformableFilter filter)
-
purgeArtifacts
private void purgeArtifacts(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> artifacts)
-
reResolveArtifacts
private void reResolveArtifacts(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> artifacts) throws org.apache.maven.artifact.resolver.ArtifactResolutionException- Throws:
org.apache.maven.artifact.resolver.ArtifactResolutionException
-
findDeleteTarget
private java.io.File findDeleteTarget(org.apache.maven.artifact.Artifact artifact)
-
verbose
private void verbose(java.lang.String message)
-
getProjectKey
private java.lang.String getProjectKey(org.apache.maven.project.MavenProject project)
-
isSkip
public boolean isSkip()
- Returns:
skip
-
setSkip
public void setSkip(boolean skip)
- Parameters:
skip-skip
-
-