如何从 Maven 的目标目录中删除生成的构建工件?

发布于 2024-08-06 23:12:48 字数 214 浏览 4 评论 0原文

如何从 Maven 的目标目录中删除生成的构建工件? Maven 生成 jar 或 war 文件到目标目录。我想在 maven 将 jar/war 文件安装到本地存储库后(即,在 maven 执行“安装”目标之后)删除该文件。删除可能发生在安装目标或我手动执行的单独目标时。

请注意,我想保留目标目录的其他部分不变,例如 target/site 和 target/surefire-reports。

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 file 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁梦 2024-08-13 23:12:49

Maven 中没有内置任何东西可以做到这一点。您可以使用 antrun 插件在安装后执行删除的 Ant 脚本工件,或使用 exec 插件来使用该命令行删除工件,或者编写自己的插件。

我认为做这些事情没有什么价值(如果有的话)。 Maven 旨在将中间和最终工件放置在 target 中,以使后续构建更加高效。由于目前还没有可用的方法来执行此操作,因此表明此操作的价值不大。如果它对您有价值,您有几种选择。

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.

伪装你 2024-08-13 23:12:49

我知道我来晚了一点。但我猜问题是,maven 项目会自动归档工件。就我而言,我禁用了自动归档,只是使用构建后操作手动归档工件。这样,只有我感兴趣的工件才会被存档。我愿意将生成的工件保留在磁盘上,直到下一个构建运行。

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.

烟凡古楼 2024-08-13 23:12:48

只需使用 clean 插件并在安装阶段后运行执行即可:

  <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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文