java 强制 Maven 清洁

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3624446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:42:39  来源:igfitidea点击:

Force Maven clean

javamaven-2release

提问by n002213f

I have a project with 2 profiles, because UAT and PROD use different versions of the same jar.

我有一个包含 2 个配置文件的项目,因为 UAT 和 PROD 使用同一个 jar 的不同版本。

I have noticed that if i don't explicitly call mvn clean ...the deployed EAR will have BOTH UAT and PROD jars.

我注意到,如果我不明确调用mvn clean ...已部署的 EAR 将同时拥有 UAT 和 PROD 罐子。

Is there a way in the POM to specify that Maven should always clean before any building?

POM 中是否有一种方法可以指定 Maven 应该在任何构建之前始终进行清理?

回答by JoseK

Use the maven-clean-pluginwith the initializephase as given here

使用此处给出maven-clean-plugininitialize阶段

http://maven.apache.org/plugins/maven-clean-plugin/usage.html

http://maven.apache.org/plugins/maven-clean-plugin/usage.html

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <id>auto-clean</id>
            <phase>initialize</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

回答by Andreas Dolk

Sure. Visit the Maven clean plugin usage page, they provide an example how to run the plugin automatically during build.

当然。访问Maven 清洁插件使用页面,他们提供了如何在构建期间自动运行插件的示例。

回答by nkr1pt

Please read up on the maven lifecycleespecially the package lifecycle.

请仔细阅读Maven 生命周期,尤其是包生命周期。

The maven clean plugin you use will probably allow you to define a clean goal at a particular pahse. You can also execute for example mvn clean install -P profile

您使用的 maven clean 插件可能允许您在特定的阶段定义一个干净的目标。您还可以执行例如 mvn clean install -P profile