You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Matthew Wheaton <md...@gmail.com> on 2005/12/05 16:57:13 UTC

M2 : Dynamically adding system JARs into Maven build classpath.

Hi all,

In Maven 1.x, I could get a list of the jars in my version control
repository, and dynamically add them to the Maven build path using an ant
task.
What's important to note, is that I have all my dependency jars in a few,
KNOWN directories. I would like to be able to include all those jars,
without having to reference each one of them explicitly in a POM, or a
parent POM. Below is how I do this in Maven 1.x with the ANT task. Note
below, that I can create the ant goal, however, the last line in the goal,
seems to be only an Maven 1.x feature and not possible in Maven 2.x.

In our environment, we may have totally different people developing that the
people doing the build. When a developer adds new JARs to version control,
it will break the build, unless we manually add the reference in all the
associated POMs (or parent POMs). We're trying to avoid this, any ideas ?

Below is my Maven 1.x ANT goal.

    <goal
        name="build:SetClasspath"
        description="Sets the classpath">

    <echo message="Setting the compile classpath . . ." />

    <ant:path id="all.libs.path">

      <!-- get all the deployment libs -->
      <ant:fileset dir="${build.deployLibs}">
        <ant:include name="**/*.*" />
      </ant:fileset>

      <!-- get all the compile only libs -->
      <ant:fileset dir="${build.compileLibs}">
        <ant:include name="**/*.*" />
      </ant:fileset>
    </ant:path>

    <m:addPath id="maven.dependency.classpath" refid="all.libs.path" />


  </goal>

Re: M2 : Dynamically adding system JARs into Maven build classpath.

Posted by Martin van den Bemt <ml...@mvdb.net>.
Shit :) Your question was about maven 2...
Sorry for the noice..

Mvgr,
Martin

Martin van den Bemt wrote:
> 1) Do what you are doing now.
> 2) Create on dependencies.xml (project.xml style) with ALL artifacts and 
> dependencies.
>   (problem is that it will not download anything, in my case it was a 
> solution :)
> 3) Do something like this in a goal :
>      <u:available file="${basedir}/dependencies.xml">
>        <maven:pom var="realPom" 
> projectDescriptor="${basedir}/dependencies.xml"/>
>      </u:available>
>      <j:if test="${realPom == null}">
>        <ant:echo>dependencies.xml not found, assuming dependencies are 
> in project.xml itself!</ant:echo>
>      </j:if>
>      <j:if test="${realPom != null}">
>        ${pom.setArtifacts(realPom.artifacts)}
>        ${pom.setDependencies(realPom.dependencies)}
>      </j:if>
> 
> 5) (probably) download the libraries, if not needed, that will help.
> 6) Add the found artifacts to your classpath (instead of the one  you 
> found with ant)
> 
> I used this to seperate between source dependencies (that needed source 
> dependencies) and real jar dependencies (like commons-collections).
> 
> Don't know if it is usable for your scenario, but you can get a lot done 
> this kind of way. The problem with this solution might be a lock in to a 
> certain version of maven (in this case I know it works in 1.0.2).
> 
> In short : hope it is usefull for you ;)
> 
> Mvgr,
> Martin
> 
> Matthew Wheaton wrote:
> 
>> Hi all,
>>
>> In Maven 1.x, I could get a list of the jars in my version control
>> repository, and dynamically add them to the Maven build path using an ant
>> task.
>> What's important to note, is that I have all my dependency jars in a few,
>> KNOWN directories. I would like to be able to include all those jars,
>> without having to reference each one of them explicitly in a POM, or a
>> parent POM. Below is how I do this in Maven 1.x with the ANT task. Note
>> below, that I can create the ant goal, however, the last line in the 
>> goal,
>> seems to be only an Maven 1.x feature and not possible in Maven 2.x.
>>
>> In our environment, we may have totally different people developing 
>> that the
>> people doing the build. When a developer adds new JARs to version 
>> control,
>> it will break the build, unless we manually add the reference in all the
>> associated POMs (or parent POMs). We're trying to avoid this, any ideas ?
>>
>> Below is my Maven 1.x ANT goal.
>>
>>     <goal
>>         name="build:SetClasspath"
>>         description="Sets the classpath">
>>
>>     <echo message="Setting the compile classpath . . ." />
>>
>>     <ant:path id="all.libs.path">
>>
>>       <!-- get all the deployment libs -->
>>       <ant:fileset dir="${build.deployLibs}">
>>         <ant:include name="**/*.*" />
>>       </ant:fileset>
>>
>>       <!-- get all the compile only libs -->
>>       <ant:fileset dir="${build.compileLibs}">
>>         <ant:include name="**/*.*" />
>>       </ant:fileset>
>>     </ant:path>
>>
>>     <m:addPath id="maven.dependency.classpath" refid="all.libs.path" />
>>
>>
>>   </goal>
>>
> 
> ---------------------------------------------------------------------
> 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


Re: M2 : Dynamically adding system JARs into Maven build classpath.

Posted by Martin van den Bemt <ml...@mvdb.net>.
1) Do what you are doing now.
2) Create on dependencies.xml (project.xml style) with ALL artifacts and dependencies.
   (problem is that it will not download anything, in my case it was a solution :)
3) Do something like this in a goal : 

      <u:available file="${basedir}/dependencies.xml">
        <maven:pom var="realPom" projectDescriptor="${basedir}/dependencies.xml"/>
      </u:available>
      <j:if test="${realPom == null}">
        <ant:echo>dependencies.xml not found, assuming dependencies are in project.xml itself!</ant:echo>
      </j:if>
      <j:if test="${realPom != null}">
        ${pom.setArtifacts(realPom.artifacts)}
        ${pom.setDependencies(realPom.dependencies)}
      </j:if>

5) (probably) download the libraries, if not needed, that will help.
6) Add the found artifacts to your classpath (instead of the one  you found with ant)

I used this to seperate between source dependencies (that needed source dependencies) and real jar dependencies (like commons-collections).

Don't know if it is usable for your scenario, but you can get a lot done this kind of way. The problem with this solution might be a lock in to a certain version of maven (in this case I know it works in 1.0.2).

In short : hope it is usefull for you ;)

Mvgr,
Martin

Matthew Wheaton wrote:
> Hi all,
> 
> In Maven 1.x, I could get a list of the jars in my version control
> repository, and dynamically add them to the Maven build path using an ant
> task.
> What's important to note, is that I have all my dependency jars in a few,
> KNOWN directories. I would like to be able to include all those jars,
> without having to reference each one of them explicitly in a POM, or a
> parent POM. Below is how I do this in Maven 1.x with the ANT task. Note
> below, that I can create the ant goal, however, the last line in the goal,
> seems to be only an Maven 1.x feature and not possible in Maven 2.x.
> 
> In our environment, we may have totally different people developing that the
> people doing the build. When a developer adds new JARs to version control,
> it will break the build, unless we manually add the reference in all the
> associated POMs (or parent POMs). We're trying to avoid this, any ideas ?
> 
> Below is my Maven 1.x ANT goal.
> 
>     <goal
>         name="build:SetClasspath"
>         description="Sets the classpath">
> 
>     <echo message="Setting the compile classpath . . ." />
> 
>     <ant:path id="all.libs.path">
> 
>       <!-- get all the deployment libs -->
>       <ant:fileset dir="${build.deployLibs}">
>         <ant:include name="**/*.*" />
>       </ant:fileset>
> 
>       <!-- get all the compile only libs -->
>       <ant:fileset dir="${build.compileLibs}">
>         <ant:include name="**/*.*" />
>       </ant:fileset>
>     </ant:path>
> 
>     <m:addPath id="maven.dependency.classpath" refid="all.libs.path" />
> 
> 
>   </goal>
> 

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


Re: M2 : Dynamically adding system JARs into Maven build classpath.

Posted by Brett Porter <br...@gmail.com>.
You can implement your own dependency resolvers in Maven. This is not
something we've seen a lot of demand for, so there isn't any
documentation on how to do it at this point. This sort of request
might indicate we should implement another resolver that can be used
in this scenario (turning off the main dependency-from-repo
mechanism).

The problem with systemPath is that it completely circumvents the
dependency mechanism. The only way they are guaranteed to work is if
you only use systemPath dependencies through the whole pom, or you
never use that dependency somewhere else - otherwise there is a good
chance you might get a duplicate included, and you certainly won't get
features that the pom requires (transitive dependencies, version
ranges, etc). Your own project won't be usable by other projects as a
dependency if they want to use those features.

Hope this clarifies it.

Cheers,
Brett

On 12/6/05, Matthew Wheaton <md...@gmail.com> wrote:
> Jeff,
>
> I added a comment to that issue.
> If they take systemPath away, as he says, then that'll break me again, for
> sure.
> I'm really contemplating NOT using M2.
>
> In any case, my workaround to make it truly dynamic, is my build.bat file
> first calls an ANT script that compiles a DependencyBuilder class, which
> iterates through the jar files in my "lib" directory, and creates a string
> that has all the <dependency> entries in it. Then, I have a pom that lives
> in my "lib" project called pom-template.xml, that, while still in ANT, I
> copy to the same directory renaming to pom.xml. I filter the file using the
> ANT filter mechanism to ADD the string I just created in the
> DependencyBuilder class, giving a psuedo-dynamic discovery of dependencies.
>
> Then, I reference the "libs" project in each of the sub-projects.
>
> A little complicated, but then I don't have to manually add JARs to the
> build when the developers add them.
>
> I'll add this commentary to the issue you referenced as well.
>
> mw
>
> On 12/5/05, Jeff Jensen <je...@upstairstechnology.com> wrote:
> >
> > Yes, we do the same thing.  How to solve changed with M2.  Now, use
> > <scope>system</scope> and <systemPath>.
> >
> > I think this JIRA discusses what your issue is.  Brett described the
> > un-recommended workaround.
> >
> > http://jira.codehaus.org/browse/MNG-1471
> >
> > I look forward to reading your comments on this... :-)
> >
> >
> > Quoting Matthew Wheaton <md...@gmail.com>:
> >
> > > Hi all,
> > >
> > > In Maven 1.x, I could get a list of the jars in my version control
> > > repository, and dynamically add them to the Maven build path using an
> > ant
> > > task.
> > > What's important to note, is that I have all my dependency jars in a
> > few,
> > > KNOWN directories. I would like to be able to include all those jars,
> > > without having to reference each one of them explicitly in a POM, or a
> > > parent POM. Below is how I do this in Maven 1.x with the ANT task. Note
> > > below, that I can create the ant goal, however, the last line in the
> > goal,
> > > seems to be only an Maven 1.x feature and not possible in Maven 2.x.
> > >
> > > In our environment, we may have totally different people developing that
> > the
> > > people doing the build. When a developer adds new JARs to version
> > control,
> > > it will break the build, unless we manually add the reference in all the
> > > associated POMs (or parent POMs). We're trying to avoid this, any ideas
> > ?
> > >
> > > Below is my Maven 1.x ANT goal.
> > >
> > >     <goal
> > >         name="build:SetClasspath"
> > >         description="Sets the classpath">
> > >
> > >     <echo message="Setting the compile classpath . . ." />
> > >
> > >     <ant:path id="all.libs.path">
> > >
> > >       <!-- get all the deployment libs -->
> > >       <ant:fileset dir="${build.deployLibs}">
> > >         <ant:include name="**/*.*" />
> > >       </ant:fileset>
> > >
> > >       <!-- get all the compile only libs -->
> > >       <ant:fileset dir="${build.compileLibs}">
> > >         <ant:include name="**/*.*" />
> > >       </ant:fileset>
> > >     </ant:path>
> > >
> > >     <m:addPath id="maven.dependency.classpath" refid="all.libs.path" />
> > >
> > >
> > >   </goal>
> > >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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


Re: M2 : Dynamically adding system JARs into Maven build classpath.

Posted by Matthew Wheaton <md...@gmail.com>.
All good points Jeff, I'm going to give M2 a try with my workaround, but if
even one other thing gets in my way, I'll be reverting my build to Maven 1.x

On 12/5/05, Jeff Jensen <je...@upstairstechnology.com> wrote:
>
> Quoting Matthew Wheaton <md...@gmail.com>:
>
> > Jeff,
> >
> > I added a comment to that issue.
> > If they take systemPath away, as he says, then that'll break me again,
> for
> > sure.
> > I'm really contemplating NOT using M2.
>
> Agreed.  I am concerned about seemingly narrowly-focused use cases of
> M2.  If
> not buying into "repo only" references, then a product cannot use
> it.  Well,
> there are plenty of customers I have that it won't work at.  Flexibility
> is
> key, not one mantra.
>
> The outcome of accessing source-controlled artifacts will play a part in
> our
> decision as well.
>
> Another reason I have stopped the migration to M2 for us is there are too
> many
> JIRAs that prevent a build from happening (we have a large system under
> development [over 7300 .java files to date across all components excluding
> test
> classes, with another year of development to go on about 70 developers],
> and M2
> can't do it yet, but M1 works fine [has quirks but gets the job done
> nicely]).
>
>
> > In any case, my workaround to make it truly dynamic, is my build.batfile
> > first calls an ANT script that compiles a DependencyBuilder class, which
> > iterates through the jar files in my "lib" directory, and creates a
> string
> > that has all the <dependency> entries in it. Then, I have a pom that
> lives
> > in my "lib" project called pom-template.xml, that, while still in ANT, I
> > copy to the same directory renaming to pom.xml. I filter the file using
> the
> > ANT filter mechanism to ADD the string I just created in the
> > DependencyBuilder class, giving a psuedo-dynamic discovery of
> dependencies.
> >
> > Then, I reference the "libs" project in each of the sub-projects.
> >
> > A little complicated, but then I don't have to manually add JARs to the
> > build when the developers add them.
>
> What a PITA!!  :-|
>
>
> > I'll add this commentary to the issue you referenced as well.
>
> Thanks for your comments.  I appreciate understanding your thoughts.
>
>
> > mw
> >
> > On 12/5/05, Jeff Jensen <je...@upstairstechnology.com> wrote:
> > >
> > > Yes, we do the same thing.  How to solve changed with M2.  Now, use
> > > <scope>system</scope> and <systemPath>.
> > >
> > > I think this JIRA discusses what your issue is.  Brett described the
> > > un-recommended workaround.
> > >
> > > http://jira.codehaus.org/browse/MNG-1471
> > >
> > > I look forward to reading your comments on this... :-)
> > >
> > >
> > > Quoting Matthew Wheaton <md...@gmail.com>:
> > >
> > > > Hi all,
> > > >
> > > > In Maven 1.x, I could get a list of the jars in my version control
> > > > repository, and dynamically add them to the Maven build path using
> an
> > > ant
> > > > task.
> > > > What's important to note, is that I have all my dependency jars in a
> > > few,
> > > > KNOWN directories. I would like to be able to include all those
> jars,
> > > > without having to reference each one of them explicitly in a POM, or
> a
> > > > parent POM. Below is how I do this in Maven 1.x with the ANT task.
> Note
> > > > below, that I can create the ant goal, however, the last line in the
> > > goal,
> > > > seems to be only an Maven 1.x feature and not possible in Maven 2.x.
> > > >
> > > > In our environment, we may have totally different people developing
> that
> > > the
> > > > people doing the build. When a developer adds new JARs to version
> > > control,
> > > > it will break the build, unless we manually add the reference in all
> the
> > > > associated POMs (or parent POMs). We're trying to avoid this, any
> ideas
> > > ?
> > > >
> > > > Below is my Maven 1.x ANT goal.
> > > >
> > > >     <goal
> > > >         name="build:SetClasspath"
> > > >         description="Sets the classpath">
> > > >
> > > >     <echo message="Setting the compile classpath . . ." />
> > > >
> > > >     <ant:path id="all.libs.path">
> > > >
> > > >       <!-- get all the deployment libs -->
> > > >       <ant:fileset dir="${build.deployLibs}">
> > > >         <ant:include name="**/*.*" />
> > > >       </ant:fileset>
> > > >
> > > >       <!-- get all the compile only libs -->
> > > >       <ant:fileset dir="${build.compileLibs}">
> > > >         <ant:include name="**/*.*" />
> > > >       </ant:fileset>
> > > >     </ant:path>
> > > >
> > > >     <m:addPath id="maven.dependency.classpath" refid="all.libs.path"
> />
> > > >
> > > >
> > > >   </goal>
>
>
>
>

Re: M2 : Dynamically adding system JARs into Maven build classpath.

Posted by Matthew Wheaton <md...@gmail.com>.
Jeff,

I added a comment to that issue.
If they take systemPath away, as he says, then that'll break me again, for
sure.
I'm really contemplating NOT using M2.

In any case, my workaround to make it truly dynamic, is my build.bat file
first calls an ANT script that compiles a DependencyBuilder class, which
iterates through the jar files in my "lib" directory, and creates a string
that has all the <dependency> entries in it. Then, I have a pom that lives
in my "lib" project called pom-template.xml, that, while still in ANT, I
copy to the same directory renaming to pom.xml. I filter the file using the
ANT filter mechanism to ADD the string I just created in the
DependencyBuilder class, giving a psuedo-dynamic discovery of dependencies.

Then, I reference the "libs" project in each of the sub-projects.

A little complicated, but then I don't have to manually add JARs to the
build when the developers add them.

I'll add this commentary to the issue you referenced as well.

mw

On 12/5/05, Jeff Jensen <je...@upstairstechnology.com> wrote:
>
> Yes, we do the same thing.  How to solve changed with M2.  Now, use
> <scope>system</scope> and <systemPath>.
>
> I think this JIRA discusses what your issue is.  Brett described the
> un-recommended workaround.
>
> http://jira.codehaus.org/browse/MNG-1471
>
> I look forward to reading your comments on this... :-)
>
>
> Quoting Matthew Wheaton <md...@gmail.com>:
>
> > Hi all,
> >
> > In Maven 1.x, I could get a list of the jars in my version control
> > repository, and dynamically add them to the Maven build path using an
> ant
> > task.
> > What's important to note, is that I have all my dependency jars in a
> few,
> > KNOWN directories. I would like to be able to include all those jars,
> > without having to reference each one of them explicitly in a POM, or a
> > parent POM. Below is how I do this in Maven 1.x with the ANT task. Note
> > below, that I can create the ant goal, however, the last line in the
> goal,
> > seems to be only an Maven 1.x feature and not possible in Maven 2.x.
> >
> > In our environment, we may have totally different people developing that
> the
> > people doing the build. When a developer adds new JARs to version
> control,
> > it will break the build, unless we manually add the reference in all the
> > associated POMs (or parent POMs). We're trying to avoid this, any ideas
> ?
> >
> > Below is my Maven 1.x ANT goal.
> >
> >     <goal
> >         name="build:SetClasspath"
> >         description="Sets the classpath">
> >
> >     <echo message="Setting the compile classpath . . ." />
> >
> >     <ant:path id="all.libs.path">
> >
> >       <!-- get all the deployment libs -->
> >       <ant:fileset dir="${build.deployLibs}">
> >         <ant:include name="**/*.*" />
> >       </ant:fileset>
> >
> >       <!-- get all the compile only libs -->
> >       <ant:fileset dir="${build.compileLibs}">
> >         <ant:include name="**/*.*" />
> >       </ant:fileset>
> >     </ant:path>
> >
> >     <m:addPath id="maven.dependency.classpath" refid="all.libs.path" />
> >
> >
> >   </goal>
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: M2 : Dynamically adding system JARs into Maven build classpath.

Posted by Jeff Jensen <je...@upstairstechnology.com>.
Yes, we do the same thing.  How to solve changed with M2.  Now, use
<scope>system</scope> and <systemPath>.

I think this JIRA discusses what your issue is.  Brett described the
un-recommended workaround.

http://jira.codehaus.org/browse/MNG-1471

I look forward to reading your comments on this... :-)


Quoting Matthew Wheaton <md...@gmail.com>:

> Hi all,
>
> In Maven 1.x, I could get a list of the jars in my version control
> repository, and dynamically add them to the Maven build path using an ant
> task.
> What's important to note, is that I have all my dependency jars in a few,
> KNOWN directories. I would like to be able to include all those jars,
> without having to reference each one of them explicitly in a POM, or a
> parent POM. Below is how I do this in Maven 1.x with the ANT task. Note
> below, that I can create the ant goal, however, the last line in the goal,
> seems to be only an Maven 1.x feature and not possible in Maven 2.x.
>
> In our environment, we may have totally different people developing that the
> people doing the build. When a developer adds new JARs to version control,
> it will break the build, unless we manually add the reference in all the
> associated POMs (or parent POMs). We're trying to avoid this, any ideas ?
>
> Below is my Maven 1.x ANT goal.
>
>     <goal
>         name="build:SetClasspath"
>         description="Sets the classpath">
>
>     <echo message="Setting the compile classpath . . ." />
>
>     <ant:path id="all.libs.path">
>
>       <!-- get all the deployment libs -->
>       <ant:fileset dir="${build.deployLibs}">
>         <ant:include name="**/*.*" />
>       </ant:fileset>
>
>       <!-- get all the compile only libs -->
>       <ant:fileset dir="${build.compileLibs}">
>         <ant:include name="**/*.*" />
>       </ant:fileset>
>     </ant:path>
>
>     <m:addPath id="maven.dependency.classpath" refid="all.libs.path" />
>
>
>   </goal>
>




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