【问题标题】:How can I configure Maven (command line) and the IDE to build in different folders?如何配置 Maven(命令行)和 IDE 以在不同的文件夹中构建?
【发布时间】:2019-06-19 07:51:57
【问题描述】:

我经常在我的 IDE(仅对我正在处理的代码运行单元测试)和命令行(运行所有单元测试)之间切换。

这会导致问题:有时,mvn clean 会失败,因为 IDE 正在构建代码。或者我在 IDE 中收到关于缺少类的奇怪错误,因为 IDE 正在读取 Maven 修改过的文件。

另外,为什么 Maven 在后台构建,我无法继续在 IDE 中工作。

如何配置我的 IDE 或 Maven 以使用不同的构建文件夹?

【问题讨论】:

    标签: eclipse intellij-idea ide maven-2


    【解决方案1】:

    在您的(父)POM 中使用配置文件和此代码:

    <project>
      ...
    
      <build>
        <outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
        <testOutputDirectory>${basedir}/${target.dir}/test-classes</testOutputDirectory>
      </build>
    
      <properties>
        <target.dir>target</target.dir>
      </properties>
    
      <profiles>
        <profile>
          <id>ide-folders</id>
          <properties>
            <target.dir>target-ide</target.dir>
          </properties>
        </profile>
      </profiles>
      ...  
    

    在您的 IDE 中配置项目以在构建时启用配置文件 target-ide。现在 Maven 和 IDE 使用不同的文件夹。

    或者,您可以在 settings.xml 中启用此配置文件,并将文件夹 target-ide 设为默认值。这样,您就不必在 IDE 中修改许多项目的设置。它甚至可以在您的 CI 构建服务器上运行(它可以构建到 target-ide 中,但谁在乎呢?如果您足够关心,您也可以在那里启用配置文件)。

    注意:这是基于 jroller.com 上的博客文章,该文章已关闭。互联网档案馆有一份:https://web.archive.org/web/20150527111413/http://www.jroller.com/eu/entry/configuring_separate_maven_output_folders

    【讨论】:

      猜你喜欢
      • 2019-07-22
      • 1970-01-01
      • 2015-09-04
      • 2017-01-20
      • 2013-05-23
      • 2012-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多