tags:

views:

909

answers:

2

I would really like to make maven write the "target" folder to a different device (ramdisk), which I would normally consider to be a different path. Is there any maven2-compliant way to do this ?

I am trying to solve this problem on windows, and a maven-compliant strategy would be preferred.

+2  A: 

Actually, Maven is not as constrained as everybody thinks, all the POMs are extended of one Super POM in which is defined the name of the target folder

<build>
  <directory>target</directory>
  <outputDirectory>target/classes</outputDirectory>
  <finalName>${artifactId}-${version}</finalName>
  <testOutputDirectory>target/test-classes</testOutputDirectory>
 .
 .
 .
</build>

Of course you can overwrite with any value you want, so just go ahead and change the <directory /> element (and other related elements) in your POM

victor hugo
This really seems like something I'd like to do in my settings.xml, since it's for my workstation. But that doesn't seem to be supported ?
krosenvold
krosenvold, you could add the above to a super pom that other poms inherit from - but then it would also affect other developers using the same super pom.
Allan Lykke Christensen
+4  A: 

If you happen to have all of your projects extending a corporate parent pom, then you could try adding Yet Another Layer of Indirection as follows:

Corporate POM:

<build>
  <directory>${my.build.directory}</directory>
</build>
<properties>
  <!-- sensible default -->
  <my.build.directory>target</my.build.directory>
</properties>

In your settings.xml:

<properties>
  <!-- Personal overridden value, perhaps profile-specific -->
  <my.build.directory>/mnt/other/device/${project.groupId}-${project.artifactId}/target</my.build.directory>
</properties>

If the local POM definition takes precedence over the settings.xml definition, then you could try omitting the default value at the cost of having every Maven instance in your control (developers, build machines, etc) specify ${my.build.directory} in its settings.xml.

Brian Laframboise
Doesn't this makes the build directory for every module the same, instead of one directory per module? So if you'd do a "mvn install" (instead of "mvn clean install"), files from all previously compiled modules would end up in the result (jar)?Maybe you can solve that by doing <my.build.directory>/mnt/other/device/${artifactId}-target</my.build.directory>.(Untested!)
Wouter Coekaerts
Very good point! I'm updated the settings.xml above but also included the groupId as artifactIds occasionally overlap across projects (eg 'core', 'utils', etc)
Brian Laframboise