0

我想.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>

我希望这会在下载新工件之前清除整个存储库,最后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]

我觉得我非常接近解决方案。可能我只需要调整插件的参数标签。

谁能给个主意?

4

1 回答 1

5

如果您清理整个本地存储库,您还会删除 maven 需要的所有插件,这些插件是在 clean 运行之前下载的。您应该使用依赖项 plaugin 来删除仅作为项目依赖项的 jars:

mvn dependency:purge-local-repository

在 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> 
于 2016-07-28T08:36:36.550 回答