You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "David P. Caldwell" <da...@code.davidpcaldwell.com> on 2013/06/14 02:13:59 UTC

Is it possible to execute a POM with a different basedir?

The use case is that I have a project (actually, many projects, so I
want to be able to do this in bulk) that are source-controlled and I'd
like to be able to create a modified version of the POM in a temporary
directory and then execute that modified POM, but against the original
base directory without altering the source-controlled POM in my
source-controlled working directory.

Obviously I could do this by copying the entire source tree and then
running my modified POM, but I'd like to do this without having to
copy every file every time, as these projects are often large and I
want to be able to execute this tool routinely.

My initial attempt was to set -Dbasedir on the command line, but this
does not appear to have the effect for which I was hoping.

I can think of several imperfect workarounds, including copying the
entire source directory (expensive), generating a temporary file in
the base directory (make sure not to commit it!), overwriting the POM
(then need to repeatedly refresh from source control to restore the
original), and reading and remembering the POM, overwriting it with
the updated version, running Maven, and then overwriting the updates
with the original (hope the process doesn't crash in a way that
prevents me from restoring the original). I'd probably lean toward the
last but it's more cumbersome and error-prone than I'd like. Is what
I'd like possible?

-- David Caldwell
http://www.davidpcaldwell.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Is it possible to execute a POM with a different basedir?

Posted by Ron Wheeler <rw...@artifact-software.com>.
On 14/06/2013 10:40 AM, David P. Caldwell wrote:
> Ron asks:
>
>> Why?
>> What is the problem that you are actually trying to solve?
> I explained it at more length in the original question, but more
> succinctly: I want to be able to execute a project with an arbitrary
> POM file without modifying the original source repository or source
> working directory in any way (including modifying the configuration of
> ignored files, which someone mentioned as a possibility). I want to
> generate this POM file at runtime by reading the original file and
> making various kinds of transformations to it, mostly involving
> altering project dependencies and/or specifying additional plugins.

I got that in the original post but why?
What software development problem are you trying to solve?

I am assuming that this is not some academic exercise in exploring the 
limits of maven and that you have a real world software development need.
If you can tell us this, there might be a solution that builds the 
artifacts that you need and does not require changing the basedir.



Ron
>
> On Thu, Jun 13, 2013 at 8:13 PM, David P. Caldwell
> <da...@code.davidpcaldwell.com> wrote:
>> The use case is that I have a project (actually, many projects, so I
>> want to be able to do this in bulk) that are source-controlled and I'd
>> like to be able to create a modified version of the POM in a temporary
>> directory and then execute that modified POM, but against the original
>> base directory without altering the source-controlled POM in my
>> source-controlled working directory.
>>
>> Obviously I could do this by copying the entire source tree and then
>> running my modified POM, but I'd like to do this without having to
>> copy every file every time, as these projects are often large and I
>> want to be able to execute this tool routinely.
>>
>> My initial attempt was to set -Dbasedir on the command line, but this
>> does not appear to have the effect for which I was hoping.
>>
>> I can think of several imperfect workarounds, including copying the
>> entire source directory (expensive), generating a temporary file in
>> the base directory (make sure not to commit it!), overwriting the POM
>> (then need to repeatedly refresh from source control to restore the
>> original), and reading and remembering the POM, overwriting it with
>> the updated version, running Maven, and then overwriting the updates
>> with the original (hope the process doesn't crash in a way that
>> prevents me from restoring the original). I'd probably lean toward the
>> last but it's more cumbersome and error-prone than I'd like. Is what
>> I'd like possible?
>>
>> -- David Caldwell
>> http://www.davidpcaldwell.com/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Is it possible to execute a POM with a different basedir?

Posted by "David P. Caldwell" <da...@code.davidpcaldwell.com>.
Ron asks:

>Why?
>What is the problem that you are actually trying to solve?

I explained it at more length in the original question, but more
succinctly: I want to be able to execute a project with an arbitrary
POM file without modifying the original source repository or source
working directory in any way (including modifying the configuration of
ignored files, which someone mentioned as a possibility). I want to
generate this POM file at runtime by reading the original file and
making various kinds of transformations to it, mostly involving
altering project dependencies and/or specifying additional plugins.

On Thu, Jun 13, 2013 at 8:13 PM, David P. Caldwell
<da...@code.davidpcaldwell.com> wrote:
> The use case is that I have a project (actually, many projects, so I
> want to be able to do this in bulk) that are source-controlled and I'd
> like to be able to create a modified version of the POM in a temporary
> directory and then execute that modified POM, but against the original
> base directory without altering the source-controlled POM in my
> source-controlled working directory.
>
> Obviously I could do this by copying the entire source tree and then
> running my modified POM, but I'd like to do this without having to
> copy every file every time, as these projects are often large and I
> want to be able to execute this tool routinely.
>
> My initial attempt was to set -Dbasedir on the command line, but this
> does not appear to have the effect for which I was hoping.
>
> I can think of several imperfect workarounds, including copying the
> entire source directory (expensive), generating a temporary file in
> the base directory (make sure not to commit it!), overwriting the POM
> (then need to repeatedly refresh from source control to restore the
> original), and reading and remembering the POM, overwriting it with
> the updated version, running Maven, and then overwriting the updates
> with the original (hope the process doesn't crash in a way that
> prevents me from restoring the original). I'd probably lean toward the
> last but it's more cumbersome and error-prone than I'd like. Is what
> I'd like possible?
>
> -- David Caldwell
> http://www.davidpcaldwell.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Is it possible to execute a POM with a different basedir?

Posted by Baptiste Mathus <bm...@gmail.com>.
I think this is what the sonar maven plugin does. Maybe you should have a
look at its sources.

My 2 cents.

Cheers
Le 14 juin 2013 03:20, "Jeff Jensen" <je...@upstairstechnology.com> a
écrit :

> Have you tried the mvn -f param?  mvn -f path/to/pom/generated.pom from the
> source tree base dir.  Inverts what you are thinking of...
>
>
>
>
> On Thu, Jun 13, 2013 at 7:13 PM, David P. Caldwell <
> david@code.davidpcaldwell.com> wrote:
>
> > The use case is that I have a project (actually, many projects, so I
> > want to be able to do this in bulk) that are source-controlled and I'd
> > like to be able to create a modified version of the POM in a temporary
> > directory and then execute that modified POM, but against the original
> > base directory without altering the source-controlled POM in my
> > source-controlled working directory.
> >
> > Obviously I could do this by copying the entire source tree and then
> > running my modified POM, but I'd like to do this without having to
> > copy every file every time, as these projects are often large and I
> > want to be able to execute this tool routinely.
> >
> > My initial attempt was to set -Dbasedir on the command line, but this
> > does not appear to have the effect for which I was hoping.
> >
> > I can think of several imperfect workarounds, including copying the
> > entire source directory (expensive), generating a temporary file in
> > the base directory (make sure not to commit it!), overwriting the POM
> > (then need to repeatedly refresh from source control to restore the
> > original), and reading and remembering the POM, overwriting it with
> > the updated version, running Maven, and then overwriting the updates
> > with the original (hope the process doesn't crash in a way that
> > prevents me from restoring the original). I'd probably lean toward the
> > last but it's more cumbersome and error-prone than I'd like. Is what
> > I'd like possible?
> >
> > -- David Caldwell
> > http://www.davidpcaldwell.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>

Re: Is it possible to execute a POM with a different basedir?

Posted by Jeff Jensen <je...@upstairstechnology.com>.
Have you tried the mvn -f param?  mvn -f path/to/pom/generated.pom from the
source tree base dir.  Inverts what you are thinking of...




On Thu, Jun 13, 2013 at 7:13 PM, David P. Caldwell <
david@code.davidpcaldwell.com> wrote:

> The use case is that I have a project (actually, many projects, so I
> want to be able to do this in bulk) that are source-controlled and I'd
> like to be able to create a modified version of the POM in a temporary
> directory and then execute that modified POM, but against the original
> base directory without altering the source-controlled POM in my
> source-controlled working directory.
>
> Obviously I could do this by copying the entire source tree and then
> running my modified POM, but I'd like to do this without having to
> copy every file every time, as these projects are often large and I
> want to be able to execute this tool routinely.
>
> My initial attempt was to set -Dbasedir on the command line, but this
> does not appear to have the effect for which I was hoping.
>
> I can think of several imperfect workarounds, including copying the
> entire source directory (expensive), generating a temporary file in
> the base directory (make sure not to commit it!), overwriting the POM
> (then need to repeatedly refresh from source control to restore the
> original), and reading and remembering the POM, overwriting it with
> the updated version, running Maven, and then overwriting the updates
> with the original (hope the process doesn't crash in a way that
> prevents me from restoring the original). I'd probably lean toward the
> last but it's more cumbersome and error-prone than I'd like. Is what
> I'd like possible?
>
> -- David Caldwell
> http://www.davidpcaldwell.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Is it possible to execute a POM with a different basedir?

Posted by "David P. Caldwell" <da...@code.davidpcaldwell.com>.
Replies:

To Jeff: Yes, that doesn't work; it still assumes the basedir is the
parent directory of the POM.

To Baptiste: I'll look into it, thanks for the pointer.

On Thu, Jun 13, 2013 at 8:13 PM, David P. Caldwell
<da...@code.davidpcaldwell.com> wrote:
> The use case is that I have a project (actually, many projects, so I
> want to be able to do this in bulk) that are source-controlled and I'd
> like to be able to create a modified version of the POM in a temporary
> directory and then execute that modified POM, but against the original
> base directory without altering the source-controlled POM in my
> source-controlled working directory.
>
> Obviously I could do this by copying the entire source tree and then
> running my modified POM, but I'd like to do this without having to
> copy every file every time, as these projects are often large and I
> want to be able to execute this tool routinely.
>
> My initial attempt was to set -Dbasedir on the command line, but this
> does not appear to have the effect for which I was hoping.
>
> I can think of several imperfect workarounds, including copying the
> entire source directory (expensive), generating a temporary file in
> the base directory (make sure not to commit it!), overwriting the POM
> (then need to repeatedly refresh from source control to restore the
> original), and reading and remembering the POM, overwriting it with
> the updated version, running Maven, and then overwriting the updates
> with the original (hope the process doesn't crash in a way that
> prevents me from restoring the original). I'd probably lean toward the
> last but it's more cumbersome and error-prone than I'd like. Is what
> I'd like possible?
>
> -- David Caldwell
> http://www.davidpcaldwell.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Is it possible to execute a POM with a different basedir?

Posted by Ron Wheeler <rw...@artifact-software.com>.
On 14/06/2013 6:02 AM, Jörg Schaible wrote:
> Hi David,
>
> David P. Caldwell wrote:
>
>> The use case is that I have a project (actually, many projects, so I
>> want to be able to do this in bulk) that are source-controlled and I'd
>> like to be able to create a modified version of the POM in a temporary
>> directory and then execute that modified POM, but against the original
>> base directory without altering the source-controlled POM in my
>> source-controlled working directory.

Why?
What is the problem that you are actually trying to solve?


>>
>> Obviously I could do this by copying the entire source tree and then
>> running my modified POM, but I'd like to do this without having to
>> copy every file every time, as these projects are often large and I
>> want to be able to execute this tool routinely.
>>
>> My initial attempt was to set -Dbasedir on the command line, but this
>> does not appear to have the effect for which I was hoping.
>>
>> I can think of several imperfect workarounds, including copying the
>> entire source directory (expensive), generating a temporary file in
>> the base directory (make sure not to commit it!), overwriting the POM
>> (then need to repeatedly refresh from source control to restore the
>> original), and reading and remembering the POM, overwriting it with
>> the updated version, running Maven, and then overwriting the updates
>> with the original (hope the process doesn't crash in a way that
>> prevents me from restoring the original). I'd probably lean toward the
>> last but it's more cumbersome and error-prone than I'd like. Is what
>> I'd like possible?
> You cannot modify the basedir, i.e your generated POM has to be at same
> location with a different name. You might select a name pattern that is
> ignored by your SCM e.g. pom.tmp. As Jeff said, call Maven like
>
> mvn -f pom.tmp
>
> However, keep in mind that this does not work in multi-project modules,
> since the modules will always refer the original parent, unless you
> overwrite the relativePath element (IIRC you can also define a POM file
> directly).
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Is it possible to execute a POM with a different basedir?

Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi David,

David P. Caldwell wrote:

> The use case is that I have a project (actually, many projects, so I
> want to be able to do this in bulk) that are source-controlled and I'd
> like to be able to create a modified version of the POM in a temporary
> directory and then execute that modified POM, but against the original
> base directory without altering the source-controlled POM in my
> source-controlled working directory.
> 
> Obviously I could do this by copying the entire source tree and then
> running my modified POM, but I'd like to do this without having to
> copy every file every time, as these projects are often large and I
> want to be able to execute this tool routinely.
> 
> My initial attempt was to set -Dbasedir on the command line, but this
> does not appear to have the effect for which I was hoping.
> 
> I can think of several imperfect workarounds, including copying the
> entire source directory (expensive), generating a temporary file in
> the base directory (make sure not to commit it!), overwriting the POM
> (then need to repeatedly refresh from source control to restore the
> original), and reading and remembering the POM, overwriting it with
> the updated version, running Maven, and then overwriting the updates
> with the original (hope the process doesn't crash in a way that
> prevents me from restoring the original). I'd probably lean toward the
> last but it's more cumbersome and error-prone than I'd like. Is what
> I'd like possible?

You cannot modify the basedir, i.e your generated POM has to be at same 
location with a different name. You might select a name pattern that is 
ignored by your SCM e.g. pom.tmp. As Jeff said, call Maven like

mvn -f pom.tmp

However, keep in mind that this does not work in multi-project modules, 
since the modules will always refer the original parent, unless you 
overwrite the relativePath element (IIRC you can also define a POM file 
directly).

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org