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.AbstractMojo
When 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 ClassesModifier and TypeClassDescriptionprivate class
Includes only direct project dependencies.private static class
Includes only snapshot artifacts -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Whether this mojo should act on all transitive dependencies.private static final String
private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager
Artifact handler manager.private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver
The artifact resolver used to re-resolve dependencies, if that option is enabled.private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver
The dependency resolverprivate String
Comma-separated list of groupId:artifactId entries, which should be used to exclude artifacts from deletion/refresh.The list of dependencies in the form of groupId:artifactId which should NOT be deleted/refreshed.private static final String
private String
Comma-separated list of groupId:artifactId entries, which should be used to include artifacts for deletion/refresh.The list of dependencies in the form of groupId:artifactId which should BE deleted/refreshed.private org.apache.maven.artifact.repository.ArtifactRepository
The local repository, from which to delete artifacts.private String
Comma-separated list of groupId:artifactId entries, which should be used to manually include artifacts for deletion.The list of dependencies in the form of groupId:artifactId which should BE deleted/purged from the local repository.private org.apache.maven.plugin.MojoExecution
This mojo execution, used to determine if it was launched from the lifecycle or the command-line.private org.apache.maven.project.MavenProject
The current Maven project.private List<org.apache.maven.project.MavenProject>
The Maven projects in the reactor.private boolean
Whether to re-resolve the artifacts once they have been deleted from the local repository.private String
Determines how liberally the plugin will delete an artifact from the local repository.private org.apache.maven.execution.MavenSession
private boolean
Skip plugin execution completely.private boolean
Whether to purge only snapshot artifacts.private boolean
Whether this plugin should output verbose messages.private static final String
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.maven.shared.artifact.filter.resolve.TransformableFilter
createPurgeArtifactsFilter
(org.apache.maven.project.MavenProject theProject, List<org.apache.maven.model.Dependency> dependencies, Set<org.apache.maven.artifact.Artifact> purgedArtifacts) Create the includes exclude filter to use when resolving and purging dependencies Also excludes any "system" scope dependenciesvoid
execute()
private File
findDeleteTarget
(org.apache.maven.artifact.Artifact artifact) private String
Convert a groupId:artifactId:version to a file system pathprivate Set<org.apache.maven.artifact.Artifact>
getFilteredResolvedArtifacts
(org.apache.maven.project.MavenProject theProject, List<org.apache.maven.model.Dependency> dependencies, org.apache.maven.shared.artifact.filter.resolve.TransformableFilter filter) private String
getProjectKey
(org.apache.maven.project.MavenProject project) boolean
isSkip()
private void
manualPurge
(List<String> theIncludes) Purge/Delete artifacts from the local repository according to the given patterns.parseIncludes
(String theInclude) Convert comma separated list of includes to List objectprivate void
purgeArtifacts
(org.apache.maven.project.MavenProject theProject, Set<org.apache.maven.artifact.Artifact> artifacts) private void
purgeLocalRepository
(org.apache.maven.project.MavenProject theProject, Set<org.apache.maven.artifact.Artifact> purgedArtifacts) Purges the local repository for the dependencies in the given Maven project.private void
reResolveArtifacts
(org.apache.maven.project.MavenProject theProject, Set<org.apache.maven.artifact.Artifact> artifacts) void
setSkip
(boolean skip) private boolean
Determines if all projects in the reactor should be purged from their dependencies.private String
toPatternExcludes
(org.apache.maven.artifact.Artifact artifact) Returns a string that represents a pattern for an exclude filter for the given artifact.private void
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
VERSION_FUZZINESS
- See Also:
-
ARTIFACT_ID_FUZZINESS
- See Also:
-
GROUP_ID_FUZZINESS
- See Also:
-
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) private List<org.apache.maven.project.MavenProject> reactorProjectsThe Maven projects in the reactor. -
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe current Maven project. -
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session -
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. -
artifactHandlerManager
@Component private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManagerArtifact handler manager. -
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
Comma-separated list of groupId:artifactId entries, which should be used to manually include artifacts for deletion. This is a command-line alternative to themanualIncludes
parameter, since List parameters are not currently compatible with CLI specification.- Since:
- 2.6
-
includes
The list of dependencies in the form of groupId:artifactId which should BE deleted/refreshed.- Since:
- 2.6
-
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 theincludes
parameter, since List parameters are not currently compatible with CLI specification.- Since:
- 2.6
-
excludes
The list of dependencies in the form of groupId:artifactId which should NOT be deleted/refreshed. -
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 theexcludes
parameter, 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. -
dependencyResolver
@Component private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolverThe dependency resolver -
artifactResolver
@Component private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolverThe artifact resolver used to re-resolve dependencies, if that option is enabled. -
resolutionFuzziness
@Parameter(property="resolutionFuzziness", defaultValue="version") private 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 Details
-
PurgeLocalRepositoryMojo
public PurgeLocalRepositoryMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionException
org.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:
true
if all projects in the reactor should be purged,false
otherwise.
-
purgeLocalRepository
private void purgeLocalRepository(org.apache.maven.project.MavenProject theProject, Set<org.apache.maven.artifact.Artifact> purgedArtifacts) throws org.apache.maven.plugin.MojoFailureException Purges the local repository for the dependencies in the given Maven project.- Parameters:
theProject
- Maven project.purgedArtifacts
- The artifacts that were already purged.- Throws:
org.apache.maven.plugin.MojoFailureException
- in case of errors during the purge.
-
manualPurge
private void manualPurge(List<String> theIncludes) throws org.apache.maven.plugin.MojoExecutionException Purge/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
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, List<org.apache.maven.model.Dependency> dependencies, 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 project.dependencies
- The dependencies to use as a reference if we're excluding transitive dependenciespurgedArtifacts
- The artifacts already purged.- Returns:
- the created filter
-
toPatternExcludes
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
Convert comma separated list of includes to List object- Parameters:
theInclude
- The list of includes- Returns:
- the includes list
-
purgeArtifacts
private void purgeArtifacts(org.apache.maven.project.MavenProject theProject, Set<org.apache.maven.artifact.Artifact> artifacts) -
reResolveArtifacts
private void reResolveArtifacts(org.apache.maven.project.MavenProject theProject, Set<org.apache.maven.artifact.Artifact> artifacts) throws org.apache.maven.artifact.resolver.ArtifactResolutionException - Throws:
org.apache.maven.artifact.resolver.ArtifactResolutionException
-
findDeleteTarget
-
verbose
-
getProjectKey
-
isSkip
public boolean isSkip()- Returns:
skip
-
setSkip
public void setSkip(boolean skip) - Parameters:
skip
-skip
-