开发者

How to remove generated build artifacts from Maven's target directory?

开发者 https://www.devze.com 2022-12-08 11:43 出处:网络
How to remove generated build artifacts from Maven\'s target directory? Maven generates a jar or war file to target directory. I\'d like to remove that file after maven has installed the jar/war fil开

How to remove generated build artifacts from Maven's target directory? Maven generates a jar or war file to target directory. I'd like to remove that file after maven has installed the jar/war fil开发者_如何学编程e to local repository (that is, after maven has executed the 'install' goal). The remove could happen either at install goal or separate goal I execute manually.

Note, that I'd like leave other parts of target directory intact, for example target/site and target/surefire-reports.


Just use the clean plugin and run an execution after the install phase:

  <plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.2</version>
    <executions>
      <execution>
        <id>auto-clean</id>
        <phase>install</phase>
        <goals>
          <goal>clean</goal>
        </goals>
        <configuration>
          <filesets>
            <fileset>
              <directory>${project.build.outputDirectory}</directory>
              <includes>
                <include>**/*.jar</include>
              </includes>
            </fileset>
           </filesets>
         </configuration>
      </execution>
    </executions>
  </plugin>


There is nothing built into Maven that can do this. You could use the antrun plugin to execute an Ant script after install that deletes the artifact, or use the exec plugin to use the command line to delete the artifact, or write your own plug-in.

I suggest there is little value, if any, in doing any of these things. Maven is designed to place intermediate and final artifacts in target to make follow-on builds more efficient. The reason that there is nothing available to do this already is an indicator that this is of little value. If it is of value to you, you have a few options.


I know I am a little bit late. But I guess the issue was, that a maven project archives the artifacts automatically. In my case, I disabled the automatic archiving and just archived the artifacts manually using the post build actions. This way, only the artifacts that I am interested in are archived. I am willing to leave the generated artifacts on disk until the next build runs.

0

精彩评论

暂无评论...
验证码 换一张
取 消