You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Costin Caraivan <cc...@axway.com> on 2009/01/26 13:39:04 UTC

Re: Programmatically adding dependencies to a MavenProject


Maarten Storm-2 wrote:
> 
> Hello all,
> I would like to add programmatically dependencies to the MavenProject.
> I have looked in the mail archives but I could not find info on this
> topic.Is there a possible solution for this?
> Kind regards,
> Maarten Storm
> 
Hello,

I'm also interested by this and I found this example:
http://www.eclipse.org/articles/article.php?file=Article-Eclipse-and-Maven2/index.html

However, when I do it, I get a NullPointerException later on with this code:
currentArtifact = artifactFactory.createBuildArtifact(						
currentDependency.getGroupId(),  currentDependency.getArtifactId(), 
currentDependency.getVersion(), currentDependency.getType() );
 							
// Add the jar to the dependency list.
getProject().getDependencies().add(currentDependency);
    							
// Get the artifact from the remote repository if it is not available
locally. 
artifactResolver.resolve(currentArtifact,
getProject().getRemoteArtifactRepositories(), localRepository);

=> 
[ERROR] FATAL ERROR
[INFO]
------------------------------------------------------------------------
[INFO] null
[INFO]
------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException
	at
org.apache.maven.project.artifact.MavenMetadataSource.createArtifacts(MavenMetadataSource.java:327)
	at
org.apache.maven.project.MavenProject.createArtifacts(MavenProject.java:1577)
	at
org.apache.maven.plugin.DefaultPluginManager.resolveTransitiveDependencies(DefaultPluginManager.java:1409)
	at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:405)
	at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
	at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
	at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
	at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
	at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
	at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
	at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

BTW, some things are undocumented, like how to get access to artifactFactory
or artifactResolver - I had to Google this page up to be able to write that
code: http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook

Thanks for any tips.

Regards,
Costin.
-- 
View this message in context: http://www.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp21173440p21664740.html
Sent from the Maven Developers mailing list archive at Nabble.com.


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Benoit Billington <be...@gmail.com>.
extracting in generated-source didn't work but in classes did!
So I was wrong ;)

the approach seems weird but let's see how it goes



--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp215077p5773435.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Programmatically adding dependencies to a MavenProject

Posted by Manfred Moser <ma...@simpligility.com>.
> @Manfred We cannot extract the jar into target/classes because the compile
> phase will not pick anything from target/classes but use that as output
> only. (I didn't check that but It makes sense :) )
>
> @Jorg I cannot let the user set the dependency "jar" in the pom.
> 1° the extracted path is different for every aar dependency
> 2° android-maven-plugin should do it for the user as he only need to
> declare
> the aar in the pom
> 3° the aar cannot be provided as it needs to be packaged into the apk

If you extract it into generated-sources that might work.

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


Re: Programmatically adding dependencies to a MavenProject

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

Benoit Billington wrote:

> @Manfred We cannot extract the jar into target/classes because the compile
> phase will not pick anything from target/classes but use that as output
> only. (I didn't check that but It makes sense :) )

Try to extract the jar and "generated sources" add that directory with the 
build-helper as additional source or resource to fool the compiler.

> @Jorg I cannot let the user set the dependency "jar" in the pom.
> 1° the extracted path is different for every aar dependency
> 2° android-maven-plugin should do it for the user as he only need to
> declare the aar in the pom
> 3° the aar cannot be provided as it needs to be packaged into the apk

OK.

Cheers,
Jörg


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Benoit Billington <be...@gmail.com>.
@Manfred We cannot extract the jar into target/classes because the compile
phase will not pick anything from target/classes but use that as output
only. (I didn't check that but It makes sense :) )

@Jorg I cannot let the user set the dependency "jar" in the pom.
1° the extracted path is different for every aar dependency
2° android-maven-plugin should do it for the user as he only need to declare
the aar in the pom
3° the aar cannot be provided as it needs to be packaged into the apk



--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp215077p5773302.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Programmatically adding dependencies to a MavenProject

Posted by Jörg Schaible <jo...@gmx.de>.
Manfred Moser wrote:

>> Benoit Billington wrote:
>>
>>> I'm facing this problem too.
>>>
>>> Android has created a new format for its libraries called Android
>>> Archive
>>> (.aar)
>>>
>>> This format described here:
>>> http://tools.android.com/tech-docs/new-build-system/aar-format contains
>>> a
>>> "/classes.jar"
>>>
>>> How would I be able to add that classes.jar into my classpath before the
>>> compile phase as theses classes will be needed by my own classes.
>>>
>>> Using Android-Maven-Plugin we extract the .aar into target/unpack/...
>>> So I was thinking to add the classes.jar as a system scoped dependency
>>>
>>> Note:
>>> my pom contains the following dependency:
>>> <dependency>
>>> <groupId>com.example</groupId>
>>> <artifactId>my-android-lib</artifactId>
>>> <version>1.0.0</version>
>>> <type>aar</type>
>>> </dependency>
>>>
>>> I cannot add a jar dependency of the same artifactid & groupid because
>>> the
>>> aar is not grouped with a jar but contains it. so you will always find
>>> .aar only in Maven Central.
>>> <dependency>
>>> <groupId>com.example</groupId>
>>> <artifactId>my-android-lib</artifactId>
>>> <version>1.0.0</version>
>>> <type>jar</type>
>>> </dependency>
>>
>> Use a classifier ... e.g. "classes".
> 
> You are misunderstanding Joerg.

No. You have

=============== %< ===================
<dependency>
 <groupId>com.example</groupId>
 <artifactId>my-android-lib</artifactId>
 <version>1.0.0</version>
 <type>aar</type>
 <scope>provided</scope> <!-- do you need it on classpath ?? -->
</dependency>
<dependency>
 <groupId>com.example</groupId>
 <artifactId>my-android-lib</artifactId>
 <version>1.0.0</version>
 <type>jar</type>
 <scope>system</scope>
 <classifier>classes</classifier>
 <systemPath>${basedir}/target/extracted/classes.jar</systemPath>
</dependency>
=============== %< ===================

and configure the dependency plugin to extract the aar to target/extracted.

Have you tried that?

- Jörg


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Manfred Moser <ma...@simpligility.com>.
> Benoit Billington wrote:
>
>> I'm facing this problem too.
>>
>> Android has created a new format for its libraries called Android
>> Archive
>> (.aar)
>>
>> This format described here:
>> http://tools.android.com/tech-docs/new-build-system/aar-format contains
>> a
>> "/classes.jar"
>>
>> How would I be able to add that classes.jar into my classpath before the
>> compile phase as theses classes will be needed by my own classes.
>>
>> Using Android-Maven-Plugin we extract the .aar into target/unpack/...
>> So I was thinking to add the classes.jar as a system scoped dependency
>>
>> Note:
>> my pom contains the following dependency:
>> <dependency>
>> <groupId>com.example</groupId>
>> <artifactId>my-android-lib</artifactId>
>> <version>1.0.0</version>
>> <type>aar</type>
>> </dependency>
>>
>> I cannot add a jar dependency of the same artifactid & groupid because
>> the
>> aar is not grouped with a jar but contains it. so you will always find
>> .aar only in Maven Central.
>> <dependency>
>> <groupId>com.example</groupId>
>> <artifactId>my-android-lib</artifactId>
>> <version>1.0.0</version>
>> <type>jar</type>
>> </dependency>
>
> Use a classifier ... e.g. "classes".

You are misunderstanding Joerg.

We can not change the type or anything. We have a aar file that contains a
classes.jar in it. And we need to make sure that it gets put onto the
classpath for compilation and whatever and then also participates in the
rest of the lifecycle ..e.g. the class files should probably go into
target/classes and will then subsequently be picked up by the android
maven plugin among other code that just got compiled and be processed
(dexed) and then put into the apk (android application package..).

The aar also contains a lot of other things we need to deal with but that
mostly works at this stage. We are just not sure how to add the contents
of the classes.jar to the classpath so that other plugins (like the
compiler plugin) know about it.

Would it maybe even be enough to extract them to target/classes ?

manfred

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


Re: Programmatically adding dependencies to a MavenProject

Posted by Jörg Schaible <Jo...@scalaris.com>.
Benoit Billington wrote:

> I'm facing this problem too.
> 
> Android has created a new format for its libraries called Android Archive
> (.aar)
> 
> This format described here:
> http://tools.android.com/tech-docs/new-build-system/aar-format contains a
> "/classes.jar"
> 
> How would I be able to add that classes.jar into my classpath before the
> compile phase as theses classes will be needed by my own classes.
> 
> Using Android-Maven-Plugin we extract the .aar into target/unpack/...
> So I was thinking to add the classes.jar as a system scoped dependency
> 
> Note:
> my pom contains the following dependency:
> <dependency>
> <groupId>com.example</groupId>
> <artifactId>my-android-lib</artifactId>
> <version>1.0.0</version>
> <type>aar</type>
> </dependency>
> 
> I cannot add a jar dependency of the same artifactid & groupid because the
> aar is not grouped with a jar but contains it. so you will always find
> .aar only in Maven Central.
> <dependency>
> <groupId>com.example</groupId>
> <artifactId>my-android-lib</artifactId>
> <version>1.0.0</version>
> <type>jar</type>
> </dependency>

Use a classifier ... e.g. "classes".

- Jörg


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Benoit Billington <be...@gmail.com>.
I'm facing this problem too.

Android has created a new format for its libraries called Android Archive
(.aar)

This format described here:
http://tools.android.com/tech-docs/new-build-system/aar-format contains a
"/classes.jar"

How would I be able to add that classes.jar into my classpath before the
compile phase as theses classes will be needed by my own classes.

Using Android-Maven-Plugin we extract the .aar into target/unpack/...
So I was thinking to add the classes.jar as a system scoped dependency

Note:
my pom contains the following dependency:
<dependency>
	<groupId>com.example</groupId>
	<artifactId>my-android-lib</artifactId>
	<version>1.0.0</version>
	<type>aar</type>
</dependency>

I cannot add a jar dependency of the same artifactid & groupid because the
aar is not grouped with a jar but contains it. so you will always find .aar
only in Maven Central.
<dependency>
	<groupId>com.example</groupId>
	<artifactId>my-android-lib</artifactId>
	<version>1.0.0</version>
	<type>jar</type>
</dependency>


Cheers



--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp215077p5773206.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Programmatically adding dependencies to a MavenProject

Posted by sizu <sc...@gmail.com>.
Example using sed:

sed
's/<dependencies>/<dependencies>\r\n\r\n<dependency>\r\n<groupId>org.ghost4j<\/groupId>\r\n<artifactId>ghost4j<\/artifactId>\r\n<version>0.5.0<\/version>\r\n<\/dependency>\r\n/g'
pom.xml > pom2.xml

Replaces the dependencies tag with the dependencies tag followed by the new
dependency (inserts the new dependency first in the list.

Creates a new file pom2.xml with the new dependency (this can be changed to
overwrite the original file using: pom.xml > pom.xml



--
View this message in context: http://maven.40175.n5.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp215077p5772864.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Programmatically adding dependencies to a MavenProject

Posted by Jason van Zyl <jv...@sonatype.com>.
On 27-Jan-09, at 12:32 AM, Costin Caraivan wrote:

>
>
> Richard van Nieuwenhoven-2 wrote:
>>
>> Hi,
>>
>> i also had this problem, and yes Jason is right don't do it! You will
>> have all sorts of follow up problems (like some other plugins not
>> working). It will work for the normal stuff, but be sure to start  
>> your
>> plugin in the validate phase.
>>
>> Now i use a custom repository layout / repository to enable me to add
>> maven dependencies to those jars (that works also with maven 3 and  
>> all
>> other plugins keep working ;-).  But you could also try Tycho.
>>
>> http://docs.codehaus.org/display/M2ECLIPSE/Tycho+project+overview
>>
>> I am thinking of creating a sourceforge project for the repository
>> layout, if there people willing to help (like adding your needed  
>> feature
>> of embedded jars).
>>
>> regards,
>> Richard van Nieuwenhoven
>>
> Tycho being alpha certainly does not inspire confidence.
>

Then you can try the maven-bundle-plugin and see what it does.

> My main problem right now is that OSGi > Maven (in terms of  
> complexity). I
> know that Maven developers know this and are trying to solve it, but  
> I have
> a problem to solve too, and waiting for the indefinite future isn't  
> really
> an option.
>

Then you can play with the maven project instance in a plugin. And you  
can do that today in 2.0.9, just warning you that this most likely  
will not work in 3.x. You are completely free to do as you wish.

> The solution will probably be the other way around: run something  
> before the
> build to add the dependencies to the pom.xml. A more visible  
> workaround, if
> you may.
>
> Regards,
> Costin.
> -- 
> View this message in context: http://www.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp21173440p21681478.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
jason at sonatype dot com
----------------------------------------------------------

A language that doesn’t affect the way you think about programming is  
not worth knowing.

  -— Alan Perlis


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Costin Caraivan <cc...@axway.com>.

Richard van Nieuwenhoven-2 wrote:
> 
> Hi,
> 
> i also had this problem, and yes Jason is right don't do it! You will 
> have all sorts of follow up problems (like some other plugins not 
> working). It will work for the normal stuff, but be sure to start your 
> plugin in the validate phase.
> 
> Now i use a custom repository layout / repository to enable me to add 
> maven dependencies to those jars (that works also with maven 3 and all 
> other plugins keep working ;-).  But you could also try Tycho.
> 
> http://docs.codehaus.org/display/M2ECLIPSE/Tycho+project+overview
> 
> I am thinking of creating a sourceforge project for the repository 
> layout, if there people willing to help (like adding your needed feature 
> of embedded jars).
> 
> regards,
> Richard van Nieuwenhoven
> 
Tycho being alpha certainly does not inspire confidence.

My main problem right now is that OSGi > Maven (in terms of complexity). I
know that Maven developers know this and are trying to solve it, but I have
a problem to solve too, and waiting for the indefinite future isn't really
an option.

The solution will probably be the other way around: run something before the
build to add the dependencies to the pom.xml. A more visible workaround, if
you may.

Regards,
Costin.
-- 
View this message in context: http://www.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp21173440p21681478.html
Sent from the Maven Developers mailing list archive at Nabble.com.


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Richard van Nieuwenhoven <ri...@gmx.at>.
Hi,

i also had this problem, and yes Jason is right don't do it! You will 
have all sorts of follow up problems (like some other plugins not 
working). It will work for the normal stuff, but be sure to start your 
plugin in the validate phase.

Now i use a custom repository layout / repository to enable me to add 
maven dependencies to those jars (that works also with maven 3 and all 
other plugins keep working ;-).  But you could also try Tycho.

http://docs.codehaus.org/display/M2ECLIPSE/Tycho+project+overview

I am thinking of creating a sourceforge project for the repository 
layout, if there people willing to help (like adding your needed feature 
of embedded jars).

regards,
Richard van Nieuwenhoven


Costin Caraivan wrote:
> 
> Jason van Zyl-5 wrote:
>> This is a bad idea and don't count on Maven 3.x supporting this  
>> because it makes determining what the dependencies are black magic.  
>> The dependency tree and visualization tools won't work. In Maven 3.x  
>> we are likely to make the dependency set immutable post resolution  
>> phase.
>>
>> I don't feel there is any valid use case for programatically adding  
>> dependencies and if someone finds one then something is wrong with  
>> Maven itself.
>>
> 
> Use case: Eclipse bundles. They can be simple jars or jars containing jars.
> Any other ideas for getting the classes inside those inner jars visible for
> the compiler?
> eclipse.jar contains whatever.jar. whatever.jar contains classes. I want to
> compile myjar.jar using the classes in whatever.jar. I do not want (for ease
> of use, this is a request) to manually add the inside dependencies, I just
> want to add eclipse.jar (like Eclipse itself does during plugin
> development).
> 
> I think this is a legitimate use case, *so*, for my use case, could anyone
> please point out what I'm doing wrong?


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Jason van Zyl <jv...@sonatype.com>.
Look at Tycho: http://docs.codehaus.org/display/M2ECLIPSE/Tycho+user+docs

Igor can help you with making bundles.

On 26-Jan-09, at 11:18 PM, Costin Caraivan wrote:

>
>
> Jason van Zyl-5 wrote:
>>
>> This is a bad idea and don't count on Maven 3.x supporting this
>> because it makes determining what the dependencies are black magic.
>> The dependency tree and visualization tools won't work. In Maven 3.x
>> we are likely to make the dependency set immutable post resolution
>> phase.
>>
>> I don't feel there is any valid use case for programatically adding
>> dependencies and if someone finds one then something is wrong with
>> Maven itself.
>>
>
> Use case: Eclipse bundles. They can be simple jars or jars  
> containing jars.
> Any other ideas for getting the classes inside those inner jars  
> visible for
> the compiler?
> eclipse.jar contains whatever.jar. whatever.jar contains classes. I  
> want to
> compile myjar.jar using the classes in whatever.jar. I do not want  
> (for ease
> of use, this is a request) to manually add the inside dependencies,  
> I just
> want to add eclipse.jar (like Eclipse itself does during plugin
> development).
>
> I think this is a legitimate use case, *so*, for my use case, could  
> anyone
> please point out what I'm doing wrong?
> -- 
> View this message in context: http://www.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp21173440p21680711.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
jason at sonatype dot com
----------------------------------------------------------

We all have problems. How we deal with them is a measure of our worth.

  -- Unknown


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Costin Caraivan <cc...@axway.com>.

Jason van Zyl-5 wrote:
> 
> This is a bad idea and don't count on Maven 3.x supporting this  
> because it makes determining what the dependencies are black magic.  
> The dependency tree and visualization tools won't work. In Maven 3.x  
> we are likely to make the dependency set immutable post resolution  
> phase.
> 
> I don't feel there is any valid use case for programatically adding  
> dependencies and if someone finds one then something is wrong with  
> Maven itself.
> 

Use case: Eclipse bundles. They can be simple jars or jars containing jars.
Any other ideas for getting the classes inside those inner jars visible for
the compiler?
eclipse.jar contains whatever.jar. whatever.jar contains classes. I want to
compile myjar.jar using the classes in whatever.jar. I do not want (for ease
of use, this is a request) to manually add the inside dependencies, I just
want to add eclipse.jar (like Eclipse itself does during plugin
development).

I think this is a legitimate use case, *so*, for my use case, could anyone
please point out what I'm doing wrong?
-- 
View this message in context: http://www.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp21173440p21680711.html
Sent from the Maven Developers mailing list archive at Nabble.com.


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Jason van Zyl <jv...@sonatype.com>.
The alpha-2 will be released when we get the last couple issues done.  
As for the final release date, no idea yet.

On 26-Jan-09, at 12:53 PM, Tom Huybrechts wrote:

> On Mon, Jan 26, 2009 at 9:23 PM, Maarten Storm <mt...@gmail.com>  
> wrote:
>> Yes it is a bad idea to add add dependencies programatically, I had a
>> RTFM thing :-( . The Pom must be the project model in all cases. Oeps
>> and sorry for that. I fixed the issue by using the scope import  
>> stated
>> somewhere in the conversation. Maybe a stupid question when will  
>> Maven
>> 3 be released?
>>
>> Kind regards,
>> Maarten Storm
>>
>
> Maven 3 will be released somewhere between january and december. The
> exact year is not known yet ;)
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
jason at sonatype dot com
----------------------------------------------------------

happiness is like a butterfly: the more you chase it, the more it will
elude you, but if you turn your attention to other things, it will come
and sit softly on your shoulder ...

  -- Thoreau


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


Re: Programmatically adding dependencies to a MavenProject

Posted by Tom Huybrechts <to...@gmail.com>.
On Mon, Jan 26, 2009 at 9:23 PM, Maarten Storm <mt...@gmail.com> wrote:
> Yes it is a bad idea to add add dependencies programatically, I had a
> RTFM thing :-( . The Pom must be the project model in all cases. Oeps
> and sorry for that. I fixed the issue by using the scope import stated
> somewhere in the conversation. Maybe a stupid question when will Maven
> 3 be released?
>
> Kind regards,
> Maarten Storm
>

Maven 3 will be released somewhere between january and december. The
exact year is not known yet ;)

Tom

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


Re: Programmatically adding dependencies to a MavenProject

Posted by Maarten Storm <mt...@gmail.com>.
Yes it is a bad idea to add add dependencies programatically, I had a
RTFM thing :-( . The Pom must be the project model in all cases. Oeps
and sorry for that. I fixed the issue by using the scope import stated
somewhere in the conversation. Maybe a stupid question when will Maven
3 be released?

Kind regards,
Maarten Storm

On Mon, Jan 26, 2009 at 5:36 PM, Jason van Zyl <jv...@sonatype.com> wrote:
> This is a bad idea and don't count on Maven 3.x supporting this because it
> makes determining what the dependencies are black magic. The dependency tree
> and visualization tools won't work. In Maven 3.x we are likely to make the
> dependency set immutable post resolution phase.
>
> I don't feel there is any valid use case for programatically adding
> dependencies and if someone finds one then something is wrong with Maven
> itself.
>
> On 26-Jan-09, at 4:39 AM, Costin Caraivan wrote:
>
>>
>>
>> Maarten Storm-2 wrote:
>>>
>>> Hello all,
>>> I would like to add programmatically dependencies to the MavenProject.
>>> I have looked in the mail archives but I could not find info on this
>>> topic.Is there a possible solution for this?
>>> Kind regards,
>>> Maarten Storm
>>>
>> Hello,
>>
>> I'm also interested by this and I found this example:
>>
>> http://www.eclipse.org/articles/article.php?file=Article-Eclipse-and-Maven2/index.html
>>
>> However, when I do it, I get a NullPointerException later on with this
>> code:
>> currentArtifact = artifactFactory.createBuildArtifact(
>>
>> currentDependency.getGroupId(),  currentDependency.getArtifactId(),
>> currentDependency.getVersion(), currentDependency.getType() );
>>
>> // Add the jar to the dependency list.
>> getProject().getDependencies().add(currentDependency);
>>
>> // Get the artifact from the remote repository if it is not available
>> locally.
>> artifactResolver.resolve(currentArtifact,
>> getProject().getRemoteArtifactRepositories(), localRepository);
>>
>> =>
>> [ERROR] FATAL ERROR
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] null
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] Trace
>> java.lang.NullPointerException
>>        at
>>
>> org.apache.maven.project.artifact.MavenMetadataSource.createArtifacts(MavenMetadataSource.java:327)
>>        at
>>
>> org.apache.maven.project.MavenProject.createArtifacts(MavenProject.java:1577)
>>        at
>>
>> org.apache.maven.plugin.DefaultPluginManager.resolveTransitiveDependencies(DefaultPluginManager.java:1409)
>>        at
>>
>> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:405)
>>        at
>>
>> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
>>        at
>>
>> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
>>        at
>>
>> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
>>        at
>>
>> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
>>        at
>>
>> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
>>        at
>>
>> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
>>        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
>>        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
>>        at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
>>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>        at
>>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>        at
>>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>        at java.lang.reflect.Method.invoke(Method.java:585)
>>        at
>> org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
>>        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
>>        at
>> org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
>>        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
>>
>> BTW, some things are undocumented, like how to get access to
>> artifactFactory
>> or artifactResolver - I had to Google this page up to be able to write
>> that
>> code: http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook
>>
>> Thanks for any tips.
>>
>> Regards,
>> Costin.
>> --
>> View this message in context:
>> http://www.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp21173440p21664740.html
>> Sent from the Maven Developers mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>
> Thanks,
>
> Jason
>
> ----------------------------------------------------------
> Jason van Zyl
> Founder,  Apache Maven
> jason at sonatype dot com
> ----------------------------------------------------------
>
> A language that doesn't affect the way you think about programming is not
> worth knowing.
>
>  -— Alan Perlis
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

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


Re: Programmatically adding dependencies to a MavenProject

Posted by Jason van Zyl <jv...@sonatype.com>.
This is a bad idea and don't count on Maven 3.x supporting this  
because it makes determining what the dependencies are black magic.  
The dependency tree and visualization tools won't work. In Maven 3.x  
we are likely to make the dependency set immutable post resolution  
phase.

I don't feel there is any valid use case for programatically adding  
dependencies and if someone finds one then something is wrong with  
Maven itself.

On 26-Jan-09, at 4:39 AM, Costin Caraivan wrote:

>
>
> Maarten Storm-2 wrote:
>>
>> Hello all,
>> I would like to add programmatically dependencies to the  
>> MavenProject.
>> I have looked in the mail archives but I could not find info on this
>> topic.Is there a possible solution for this?
>> Kind regards,
>> Maarten Storm
>>
> Hello,
>
> I'm also interested by this and I found this example:
> http://www.eclipse.org/articles/article.php?file=Article-Eclipse-and-Maven2/index.html
>
> However, when I do it, I get a NullPointerException later on with  
> this code:
> currentArtifact = artifactFactory.createBuildArtifact(						
> currentDependency.getGroupId(),  currentDependency.getArtifactId(),
> currentDependency.getVersion(), currentDependency.getType() );
> 							
> // Add the jar to the dependency list.
> getProject().getDependencies().add(currentDependency);
>    							
> // Get the artifact from the remote repository if it is not available
> locally.
> artifactResolver.resolve(currentArtifact,
> getProject().getRemoteArtifactRepositories(), localRepository);
>
> =>
> [ERROR] FATAL ERROR
> [INFO]
> ------------------------------------------------------------------------
> [INFO] null
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Trace
> java.lang.NullPointerException
> 	at
> org 
> .apache 
> .maven 
> .project 
> .artifact 
> .MavenMetadataSource.createArtifacts(MavenMetadataSource.java:327)
> 	at
> org 
> .apache.maven.project.MavenProject.createArtifacts(MavenProject.java: 
> 1577)
> 	at
> org 
> .apache 
> .maven 
> .plugin 
> .DefaultPluginManager 
> .resolveTransitiveDependencies(DefaultPluginManager.java:1409)
> 	at
> org 
> .apache 
> .maven 
> .plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java: 
> 405)
> 	at
> org 
> .apache 
> .maven 
> .lifecycle 
> .DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java: 
> 558)
> 	at
> org 
> .apache 
> .maven 
> .lifecycle 
> .DefaultLifecycleExecutor 
> .executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
> 	at
> org 
> .apache 
> .maven 
> .lifecycle 
> .DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java: 
> 478)
> 	at
> org 
> .apache 
> .maven 
> .lifecycle 
> .DefaultLifecycleExecutor 
> .executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
> 	at
> org 
> .apache 
> .maven 
> .lifecycle 
> .DefaultLifecycleExecutor 
> .executeTaskSegments(DefaultLifecycleExecutor.java:291)
> 	at
> org 
> .apache 
> .maven 
> .lifecycle 
> .DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
> 	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
> 	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
> 	at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun 
> .reflect 
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun 
> .reflect 
> .DelegatingMethodAccessorImpl 
> .invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:585)
> 	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java: 
> 315)
> 	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
> 	at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java: 
> 430)
> 	at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
>
> BTW, some things are undocumented, like how to get access to  
> artifactFactory
> or artifactResolver - I had to Google this page up to be able to  
> write that
> code: http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook
>
> Thanks for any tips.
>
> Regards,
> Costin.
> -- 
> View this message in context: http://www.nabble.com/Programmatically-adding-dependencies-to-a-MavenProject-tp21173440p21664740.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
jason at sonatype dot com
----------------------------------------------------------

A language that doesn’t affect the way you think about programming is  
not worth knowing.

  -— Alan Perlis


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