在安装阶段通过maven-plugin清除本地Maven存储库

Sch*_*tze 0 maven maven-clean-plugin

我想.m2/repository在安装阶段之前删除整个存储库()的内容。当然,我不想手工完成,因此我正在寻找一款具有魔力的插件。到目前为止,我遇到了,maven-clean-plugin并且我正尝试按以下方式使用它:

<build>
      <sourceDirectory>src/</sourceDirectory>
      <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
               <source>${jdk.version}</source>
               <target>${jdk.version}</target>
            </configuration>
        </plugin>  
        <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
        <filesets>
                  <fileset>
                      <directory>${settings.localRepository}/</directory>
                      <includes>
                          <include>**/*</include>
                      </includes>
                  </fileset>
        </filesets>
        </configuration>
        <executions>
          <execution>
            <id>auto-clean</id>
            <phase>install</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      </plugins>
   </build>
Run Code Online (Sandbox Code Playgroud)

我希望这可以在下载新的工件之前清除整个存储库,最后target从模块中删除该文件夹。删除target文件夹是可行的,但是清除存储库还是行不通的。它确实清除了存储库,但是随后Maven抱怨缺少所需的某些工件,因此编译失败并返回以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources (default-resources) on project com.google.protobuf: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.3 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-resources-plugin:jar:2.3 -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

我觉得我已经很接近解决方案了。可能我只需要调整插件的参数标签即可。

有人可以提出一个主意吗?

Jen*_*ens 5

如果您清理整个本地存储库,则还将删除maven所需的所有插件,并在清理运行之前下载了所有插件。您应该使用plaugin依赖项仅删除属于您的Project依赖项的jar:

mvn dependency:purge-local-repository
Run Code Online (Sandbox Code Playgroud)

在pom中,您可以像这样使用它:

  <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.7</version> 
    <executions> 
      <execution> 
        <id>purge-local-dependencies</id> 
        <phase>clean</phase> 
        <goals> 
          <goal>purge-local-repository</goal> 
        </goals> 
        <configuration> 
          <resolutionFuzziness>groupId</resolutionFuzziness> 
          <includes> 
            <include>org.ambraproject</include> 
          </includes> 
        </configuration> 
      </execution> 
    </executions> 
  </plugin> 
Run Code Online (Sandbox Code Playgroud)