如何配置 Maven(命令行)和 IDE 以在不同的文件夹中构建? [英] How can I configure Maven (command line) and the IDE to build in different folders?

查看:33
本文介绍了如何配置 Maven(命令行)和 IDE 以在不同的文件夹中构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm often switching between my IDE (running just the unit tests for the code which I'm working on) and the command line (running all unit tests).

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

This causes problems: Sometimes, mvn clean fails because the IDE is building the code. Or I get weird errors in the IDE about missing classes because the IDE is reading files which Maven has modified.

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

Also, I can't continue working in the IDE why Maven builds in the background.

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

How can I configure my IDE or Maven to use different build folders?

推荐答案

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

Use profiles and this code in your (parent) 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 使用不同的文件夹.

Configure the project in your IDE to enable the profile target-ide when building. Now Maven and the IDE use different folders.

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

Alternatively, you could enable this profile in your settings.xml and make the folder target-ide the default. This way, you wouldn't have to modify the settings of many projects in your IDE. It would even work on your CI build server (it would build into target-ide but who cares? And if you cared enough, you can enable the profile there as well).

注意:这是基于 jroller.com 上的博客文章,该文章已关闭.Internet 存档有一个副本:https://web.archive.org/web/20150527111413/http://www.jroller.com/eu/entry/configuring_separate_maven_output_folders

Note: This is based on a blog-post on jroller.com which is down. The Internet Archive has a copy: https://web.archive.org/web/20150527111413/http://www.jroller.com/eu/entry/configuring_separate_maven_output_folders

这篇关于如何配置 Maven(命令行)和 IDE 以在不同的文件夹中构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆