You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Marilyn Sander -X (marilysa - Digital-X, Inc. at Cisco)" <ma...@cisco.com> on 2007/01/10 21:18:02 UTC

Followup on localRepository and Maven ant tasks

The problem with the local repository and the Maven tasks for ant
is solved.   I thought I should report what I found.

The problem:  If you define the local repository in ~/.m2/settings.xml,

all builds by the same user will use the same local repository, and
builds
that run simultaneously will step all over each other.  If you want a
unique
local repository for each build, you need another method to define the 
local repository.  That is easily done with any of several methods when
invoking mvn directly.  But I needed to find one that works with the 
Maven ant tasks.

After  your ant script loads up antlib to define (and in some cases
re-define) 
the ant tasks that are will be invoking Maven, you can then define the
local repository with:
	<artifact:localRepository id="localrepo"
location="/some-location" />

Then in any task that should reference the local repository, you put in
	<artifact:dependencies>
	  <localRepository refid="localrepo" />
	</artifact:dependencies>

This is illustrated in the "sample.build.xml" file.  It is reached
through a
link on http://maven.apache.org/ant-tasks.html.  The link is toward the
bottom
of the page.  I did not recognize it as a link at first, because the
links on
that page are not set off with underscores.  I looked for it in the
antlib jar
file, but it is not in that file.  So if you look for that file, look
for the
Link.

The location attribute can be obtained from an environment variable, a
hard-coded property, or a properties file.  So you can call Maven in the
mvn 
part of the build with 
	mvn -Dmaven.repo.local=/some-location clean install

and then use /some-location in the artifact declaration for antlib.  As
far as 
I can see, this is the only way to ensure that Maven ant tasks use the
same local
Repository as the initial mvn call, other than to define the local
repository in
~/.m2/settings.xml.  

I've tentatively decided that, for every build (we do daily ones for
each of 
several products and versions of products) there should be
a fresh localRepository unique to that build.  At the end of the build,
that
local repository can be made into a tarball and stored with the build.
Then, to
re-create that build, we expand the tarball again, use it for the local
repository,
and run the Maven part of the build with the offline option.

This is scalable to allow  any given user run an arbitrary number
of builds simultaneously on any one machine or several machines, because
we
can define a unique local repository for each of the builds.  The name
and location
could be tied to the build name and number or a time stamp as well as or
instead
of the user id.

I hope this is helpful to someone.

--Marilyn Sander

> -----Original Message-----
> From: Peter.Pilgrim@ubs.com [mailto:Peter.Pilgrim@ubs.com] 
> Sent: Monday, December 04, 2006 6:13 AM
> To: users@maven.apache.org
> Subject: RE: MAVEN_INSTALL_DIR/conf/settings.xml
> 
> 
> 
> 
> > -----Original Message-----
> > From: Marilyn Sander -X (marilysa - Digital-X, Inc. at Cisco)
> ==////==
> > 
> > > -----Original Message-----
> > > From: Peter.Pilgrim@ubs.com [mailto:Peter.Pilgrim@ubs.com]
> > > Sent: Friday, December 01, 2006 2:53 AM
> > > To: users@maven.apache.org
> > > Subject: RE: MAVEN_INSTALL_DIR/conf/settings.xml
> > > 
> > > > -----Original Message-----
> > > > From: Marilyn Sander -X (marilysa - Digital-X, Inc. at Cisco) 
> > > > [mailto:marilysa@cisco.com]
> > > > Sent: 01 December 2006 00:15
> > > > To: Maven Users List
> > > > Subject: RE: MAVEN_INSTALL_DIR/conf/settings.xml
> > > > 
> > > > I tried the suggestion below for invoking Maven and it
> > > worked.  I also
> > > > defined the maven.repo.local property in the ant script for
> > > our mixed
> > > > build, hoping antlib would pick up on it and use the same local 
> > > > repository for the Maven ant tasks.  No such luck.
> > > > 
> > > > It seems there is no way to pass the location of the local
> > > repository
> > > > to antlib except through ~/.m2/settings.xml or
> > > ~/.m2/ant/settings.xml.  
> > > > Thus there is no way to have multiple repositories per user 
> > > > simultaneously.  I will file a JIRA request for an enhancement.
> > > 
> > > Hi Jason et Al
> > > 
> > > We need to export some important system variables through Maven 2 
> > > Ant[Run] and Exec similar plugins. Perhaps the developer
> > can devise a
> > > way to create or export system variables as environment variables 
> > > generally through Maven core.
> > > 
> > > Marilyn
> > > 
> > > I also worked around this problem by using `sed' on UNIX
> > with a simple
> > > placeholder inside `settings.xml.in'.
> > > 
> > > I did it in a shell script that called Maven like this
> > > 
> > > /bin/rm -rf ${XYZ_M2_LOCAL}/settings.xml sed -e 
> > > 's,@BUILD_REPO@,'${XYZ_M2_LOCAL_REPO}',g'
> > > src/release-control/settings.xml.in  > 
> ${XYZ_M2_LOCAL}/settings.xml
> > > 
> > > The settings.xml.in looks like this, of course:
> > > 
> > > <settings xmlns="http://maven.apache.org/POM/4.0.0"
> > >   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > >   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> > >                       
> > http://maven.apache.org/xsd/settings-1.0.0.xsd">
> > > 
> > >   <localRepository>@BUILD_REPO@</localRepository>
> > > 
> > >   <interactiveMode/>
> > >   <usePluginRegistry/>
> > >   ...
> > > </setting>
> > 
> > Peter,
> > Thanks for your reply and for this suggestion.  We are 
> already doing 
> > something like that in order to keep the repositories for different 
> > builds separate.  But we still have the problem that each 
> build must 
> > be allowed to complete before another one can run for the 
> same user , 
> > because the ant tasks that use Maven can run very late in the build.
> > 
> 
> (Where are the gears grinding?)
> 
> I see: You have a build that has a dependency that relates to 
> build-time.
> Despite the fact that Maven creates it artifacts and install 
> them in a local repository, there is some other thing in your 
> corporate environment that it is time conscience.
> 
> If this is the case then what would be case if you are build 
> with Apache Ant, then this build-time dependency will still 
> exist regardless of the infrastructure technology.
> 
> I am not sure, then, if Maven can solve this, especially f 
> you cannot isolate the build-time dependency.
> 
> Having said, I think a user-profile related dependency can be 
> a problem for you. If you a user-profile that shared between 
> teams, divisions, departments then the environment variables 
> can be changed ad hoc. Therefore again Maven cannot 
> 
> > I've filed the JIRA request.  I got the automated acknowledgment 
> > (MNG-2684), but that's all so far.
> > --Marilyn
> > > 
> > > > 
> > > > Meantime, our mixed builds are not scalable at all.  We
> > can do only
> > > > one build per user per machine at a time.  I hope the
> > > enhancement will
> > > > come through fairly quickly.
> > > >
> > > 
> > >  
> > > ==////==
> > > 
> > > --
> > > Peter Pilgrim
> > > UBS Investment Bank,
> > > PTS Portal / IT FIRC OPS LDN,
> > > 100 Liverpool Street, London EC2M 2RH, United Kingdom
> > > +44 (0) 20 75 75692
> > > :: Java EE / E-Commerce / Enterprise Integration / Development ::
> > > 
> > > Visit our website at http://www.ubs.com
> > > 
> > > This message contains confidential information and is 
> intended only 
> > > for the individual named.  If you are not the named addressee you 
> > > should not disseminate, distribute or copy this e-mail.
> > Please notify
> > > the sender immediately by e-mail if you have received this
> > e-mail by
> > > mistake and delete this e-mail from your system.
> > > 
> > > E-mail transmission cannot be guaranteed to be secure or
> > error-free as
> > > information could be intercepted, corrupted, lost,
> > destroyed, arrive
> > > late or incomplete, or contain viruses.  The sender
> > therefore does not
> > > accept liability for any errors or omissions in the
> > contents of this
> > > message which arise as a result of e-mail transmission.  If 
> > > verification is required please request a hard-copy 
> version.  This 
> > > message is provided for informational purposes and should not be 
> > > construed as a solicitation or offer to buy or sell any
> > securities or
> > > related financial instruments.
> > > 
> > > 
> > > 
> > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> > 
> > 
> --
> Peter Pilgrim
> UBS Investment Bank,
> PTS Portal / IT FIRC OPS LDN,
> 100 Liverpool Street, London EC2M 2RH, United Kingdom
> +44 (0) 20 75 75692
> :: Java EE / E-Commerce / Enterprise Integration / Development ::
>  
> 
> Visit our website at http://www.ubs.com
> 
> This message contains confidential information and is 
> intended only for the individual named.  If you are not the 
> named addressee you should not disseminate, distribute or 
> copy this e-mail.  Please notify the sender immediately by 
> e-mail if you have received this e-mail by mistake and delete 
> this e-mail from your system.
> 
> E-mail transmission cannot be guaranteed to be secure or 
> error-free as information could be intercepted, corrupted, 
> lost, destroyed, arrive late or incomplete, or contain 
> viruses.  The sender therefore does not accept liability for 
> any errors or omissions in the contents of this message which 
> arise as a result of e-mail transmission.  If verification is 
> required please request a hard-copy version.  This message is 
> provided for informational purposes and should not be 
> construed as a solicitation or offer to buy or sell any 
> securities or related financial instruments.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 

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