Wednesday, April 27, 2011

That blasted maven target directory

[WARN] Slightly thick maven discussion, incoming.

Sort of a holdover from when the normal procedure for checking in was to check in everything recursively in your local working copy tree, I just hate it when files that aren't controlled by my VCS/SCM get placed under that directory tree.
So I never do it. I've always made sure that the ant builds I make/use build artifacts OUTside that tree.
And along comes maven.
Come on, guys. What were you thinking?
Well, maybe they were thinking, "Hey, we all use modern IDE's which help partition our SVN checkins into changelists for us, so we don't *have* to checkin everything recursively. And also, we can easily run our status checks while excluding external directories and files we don't want to see."
Oh.
But still! Why not build the product up one directory and make the target directory a peer to your vcs-controlled one?

Well, it's configurable. You don't *have* to leave it as the default. It's part of the <build> element:


<build>
<directory>${project.basedir}/../target</directory>
</build>

But I don't like that on my CI build server, because builds of 2 different projects can clobber eachother's target directory (or leave junk in there). 

So what I really want is for this to happen only in a developer's environment. And only optionally.

There's a few ways to do this, but I chose to use the maven <profiles> in the pom, along with the <activeProfiles> in the developer's settings.xml.

In the pom:
<profiles>
  <profile>
    <id>dev_environment</id>
    <build>
      <directory>${project.basedir}/../target</directory>
    </build>
  </profile>
</profiles>

And in the settings.xml:
<activeProfiles>
  <activeProfile>dev_environment</activeProfile>
</activeProfiles>

No comments:

Post a Comment