Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain project directory in a maven mojo?

Tags:

maven-plugin

I'm trying to enclose some legacy code in a maven plugin. The legacy code is writing its outputs in the OS current working directory. I want to move all that into the target dir. I.e. if my project nesting is

A
-B
-C

and I run mvn install in B or C, I get the outputs in B or C and want to move them to B/target and C/target. Even worse, if I launch mvn install in A, outputs for both B and C wind up in A, which is obviously very bad (overwrites).

I've looked for a way to get the current project folder (not the place mvn install was launched from), but have found nothing so far that doesn't involve pushing this all back at the user (command line hacks, pom hacks, properties files, etc). I've also wished for a way to change the working directory before launching the legacy, but Java doesn't allow that. So how should I proceed?

like image 847
Bradjcox Avatar asked Dec 12 '12 12:12

Bradjcox


1 Answers

Just a quick note: for latest maven plugins, annotations could be used instead:

@Parameter(readonly = true, defaultValue = "${project}")
private MavenProject project;
like image 85
Panayotis Avatar answered Jan 04 '23 04:01

Panayotis