You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by sizu <sc...@gmail.com> on 2013/10/11 20:46:03 UTC

Re: Programmatically adding dependencies to a MavenProject

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 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