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 Classes Modifier and Type Class Description private class
PurgeLocalRepositoryMojo.DirectDependencyFilter
Includes only direct project dependencies.private static class
PurgeLocalRepositoryMojo.SnapshotsFilter
Includes only snapshot artifacts
-
Field Summary
Fields Modifier and Type Field Description private boolean
actTransitively
Whether this mojo should act on all transitive dependencies.private static java.lang.String
ARTIFACT_ID_FUZZINESS
private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager
artifactHandlerManager
Artifact handler manager.private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver
artifactResolver
The artifact resolver used to re-resolve dependencies, if that option is enabled.private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver
dependencyResolver
The dependency resolverprivate java.lang.String
exclude
Comma-separated list of groupId:artifactId entries, which should be used to exclude artifacts from deletion/refresh.private java.util.List<java.lang.String>
excludes
The list of dependencies in the form of groupId:artifactId which should NOT be deleted/refreshed.private static java.lang.String
GROUP_ID_FUZZINESS
private java.lang.String
include
Comma-separated list of groupId:artifactId entries, which should be used to include artifacts for deletion/refresh.private java.util.List<java.lang.String>
includes
The list of dependencies in the form of groupId:artifactId which should BE deleted/refreshed.private org.apache.maven.artifact.repository.ArtifactRepository
localRepository
The local repository, from which to delete artifacts.private java.lang.String
manualInclude
Comma-separated list of groupId:artifactId entries, which should be used to manually include artifacts for deletion.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.private org.apache.maven.plugin.MojoExecution
mojoExecution
This mojo execution, used to determine if it was launched from the lifecycle or the command-line.private org.apache.maven.project.MavenProject
project
The current Maven project.private java.util.List<org.apache.maven.project.MavenProject>
reactorProjects
The Maven projects in the reactor.private boolean
reResolve
Whether to re-resolve the artifacts once they have been deleted from the local repository.private java.lang.String
resolutionFuzziness
Determines how liberally the plugin will delete an artifact from the local repository.private org.apache.maven.execution.MavenSession
session
private boolean
skip
Skip plugin execution completely.private boolean
snapshotsOnly
Whether to purge only snapshot artifacts.private boolean
verbose
Whether this plugin should output verbose messages.private static java.lang.String
VERSION_FUZZINESS
-
Constructor Summary
Constructors Constructor Description PurgeLocalRepositoryMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 dependenciesvoid
execute()
private java.io.File
findDeleteTarget(org.apache.maven.artifact.Artifact artifact)
private java.lang.String
gavToPath(java.lang.String gav)
Convert a groupId:artifactId:version to a file system pathprivate 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.String
getProjectKey(org.apache.maven.project.MavenProject project)
boolean
isSkip()
private void
manualPurge(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 objectprivate void
purgeArtifacts(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> artifacts)
private void
purgeLocalRepository(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 void
reResolveArtifacts(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> artifacts, org.apache.maven.artifact.resolver.filter.ArtifactFilter filter)
void
setSkip(boolean skip)
private boolean
shouldPurgeAllProjectsInReactor()
Determines if all projects in the reactor should be purged from their dependencies.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.private void
verbose(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
-
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) private java.util.List<org.apache.maven.project.MavenProject> reactorProjects
The Maven projects in the reactor.
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
The 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 mojoExecution
This 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 artifactHandlerManager
Artifact handler manager.
-
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 themanualIncludes
parameter, 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 theincludes
parameter, 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 theexcludes
parameter, since List parameters are not currently compatible with CLI specification.
-
reResolve
@Parameter(property="reResolve", defaultValue="true") private boolean reResolve
Whether 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 localRepository
The local repository, from which to delete artifacts.
-
dependencyResolver
@Component private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolver
The dependency resolver
-
artifactResolver
@Component private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolver
The artifact resolver used to re-resolve dependencies, if that option is enabled.
-
resolutionFuzziness
@Parameter(property="resolutionFuzziness", defaultValue="version") private java.lang.String resolutionFuzziness
Determines 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 actTransitively
Whether this mojo should act on all transitive dependencies. Default value is true.
-
verbose
@Parameter(property="verbose", defaultValue="false") private boolean verbose
Whether this plugin should output verbose messages. Default is false.
-
snapshotsOnly
@Parameter(property="snapshotsOnly", defaultValue="false") private boolean snapshotsOnly
Whether to purge only snapshot artifacts.- Since:
- 2.4
-
skip
@Parameter(property="skip", defaultValue="false") private boolean skip
Skip plugin execution completely.- Since:
- 2.7
-
-
Method Detail
-
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, java.util.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(java.util.List<java.lang.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
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 project.dependencies
- 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) throws org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoFailureException
-
reResolveArtifacts
private void reResolveArtifacts(org.apache.maven.project.MavenProject theProject, java.util.Set<org.apache.maven.artifact.Artifact> artifacts, org.apache.maven.artifact.resolver.filter.ArtifactFilter filter) throws org.apache.maven.artifact.resolver.ArtifactResolutionException, org.apache.maven.artifact.resolver.ArtifactNotFoundException
- Throws:
org.apache.maven.artifact.resolver.ArtifactResolutionException
org.apache.maven.artifact.resolver.ArtifactNotFoundException
-
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
-
-