Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure the Maven dependency for Guice 3.0 for use without AOP?

I have an Android Maven project and want to use Google Guice 3.0 in it.

There is a "No-AOP" version of Guice, which is compatible with Android.

How can I tell maven to use the "No-AOP" version of guice?

Update 1 (03.05.2013 10:46 MSK):

When I add the dependency on Google Guice, I get following exception during the build (mvn clean install):

[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/google/inject/Abs
tractModule;
[INFO]  at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:12
3)
[INFO]  at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[INFO]  at com.android.dx.command.dexer.Main.processClass(Main.java:490)
[INFO]  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
[INFO]  at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[INFO]  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpen
er.java:245)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.j
ava:131)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java
:109)
[INFO]  at com.android.dx.command.dexer.Main.processOne(Main.java:422)
[INFO]  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
[INFO]  at com.android.dx.command.dexer.Main.run(Main.java:209)
[INFO]  at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO]  at com.android.dx.command.Main.main(Main.java:91)
[INFO] 1 error; aborting

Here are my dependencies:

<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>4.1.1.4</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>3.0</version>
        <classifier>no_aop</classifier>
    </dependency>

    <!-- Make sure this (robolectric dependency) is below the android dependencies -->
    <dependency>
        <groupId>com.pivotallabs</groupId>
        <artifactId>robolectric</artifactId>
        <version>1.0-RC4</version>
    </dependency>
    <dependency>
        <groupId>org.achartengine</groupId>
        <artifactId>achartengine</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.easytesting</groupId>
        <artifactId>fest-assert-core</artifactId>
        <version>2.0M8</version>
    </dependency>
    <dependency>
        <groupId>ru.altruix</groupId>
        <artifactId>ccp-commons</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>ru.altruix</groupId>
        <artifactId>commons</artifactId>
        <version>1.11</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.1.4</version>
    </dependency>
</dependencies>
like image 910
Dmitrii Pisarenko Avatar asked May 03 '13 06:05

Dmitrii Pisarenko


People also ask

How does Guice dependency injection work?

Guice figures out how to give you an Emailer based on the type. If it's a simple object, it'll instantiate it and pass it in. If it has dependencies, it will resolve those dependencies, pass them into it's constructor, then pass the resulting object into your object.

What is Guice dependency injection?

Guice is an open source, Java-based dependency injection framework. It is quiet lightweight and is actively developed/managed by Google. This tutorial covers most of the topics required for a basic understanding of Google Guice and to get a feel of how it works.


1 Answers

You need to specify no_aop as classifier like this:

<dependency>
   <groupId>com.google.inject</groupId>
   <artifactId>guice</artifactId>
   <version>3.0</version>
   <classifier>no_aop</classifier>
</dependency>
like image 56
Keppil Avatar answered Oct 26 '22 23:10

Keppil