0

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

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.

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

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

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820

1 Answers1

1

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

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

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

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

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820