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 
    Includes only direct project dependencies.
    private static class 
    Includes only snapshot artifacts
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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 resolver
    private String
    Comma-separated list of groupId:artifactId entries, which should be used to exclude artifacts from deletion/refresh.
    private List<String>
    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.
    private List<String>
    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.
    private List<String>
    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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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
    void
     
    private File
    findDeleteTarget(org.apache.maven.artifact.Artifact artifact)
     
    private String
    Convert a groupId:artifactId:version to a file system path
    private 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
     
    private void
    manualPurge(List<String> theIncludes)
    Purge/Delete artifacts from the local repository according to the given patterns.
    private List<String>
    parseIncludes(String theInclude)
    Convert comma separated list of includes to List object
    private 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
    verbose(String message)
     

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • VERSION_FUZZINESS

      private static final String VERSION_FUZZINESS
      See Also:
    • ARTIFACT_ID_FUZZINESS

      private static final String ARTIFACT_ID_FUZZINESS
      See Also:
    • GROUP_ID_FUZZINESS

      private static final String GROUP_ID_FUZZINESS
      See Also:
    • reactorProjects

      @Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) private 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 List<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 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 the manualIncludes parameter, since List parameters are not currently compatible with CLI specification.
      Since:
      2.6
    • includes

      @Parameter private List<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 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 the includes parameter, since List parameters are not currently compatible with CLI specification.
      Since:
      2.6
    • excludes

      @Parameter private List<String> excludes
      The list of dependencies in the form of groupId:artifactId which should NOT be deleted/refreshed.
    • exclude

      @Parameter(property="exclude") private 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 the excludes 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 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
  • 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

      private String gavToPath(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, 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 dependencies
      purgedArtifacts - The artifacts already purged.
      Returns:
      the created filter
    • toPatternExcludes

      private 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 List<String> parseIncludes(String theInclude)
      Convert comma separated list of includes to List object
      Parameters:
      theInclude - The list of includes
      Returns:
      the includes list
    • getFilteredResolvedArtifacts

      private 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)
    • 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

      private File findDeleteTarget(org.apache.maven.artifact.Artifact artifact)
    • verbose

      private void verbose(String message)
    • getProjectKey

      private String getProjectKey(org.apache.maven.project.MavenProject project)
    • isSkip

      public boolean isSkip()
      Returns:
      skip
    • setSkip

      public void setSkip(boolean skip)
      Parameters:
      skip - skip