Maven - WonderCsabo/androidannotations GitHub Wiki

This page teaches you how to configure AndroidAnnotations on an Android project that uses Maven.

Please first read the Introduction page of the android-maven-plugin.

POM configuration

The pom.xml configuration is straightforward.

Add the following dependencies:

<dependencies>
        <!-- [...] -->
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>androidannotations</artifactId>
		<version>XXX</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>androidannotations-api</artifactId>
		<version>XXX</version>
	</dependency>
</dependencies>

Make sure your project is built at least with Java 1.6:

<build>
	<plugins>
		<!-- [...] -->
		<plugin>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.1</version>
			<configuration>
				<source>1.6</source>
				<target>1.6</target>
			</configuration>
		</plugin>
	</plugins>
</build>

Adding more AA plugins

If you are using AA plugins, you can add those dependencies in this way:

<dependencies>
        <!-- [...] -->
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>{plugin-name}</artifactId>
		<version>XXX</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>{plugin-name}-api</artifactId>
		<version>XXX</version>
	</dependency>
</dependencies>

Substitute {plugin-name} with the real name of the plugin what you want to add.

Next steps

Snapshots

If you want to use snapshot versions of AndroidAnnotations, you should configure your project with the snapshot repository:

<dependencies>
        <!-- [...] -->
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>androidannotations</artifactId>
		<version>YYY-SNAPSHOT</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>androidannotations-api</artifactId>
		<version>YYY-SNAPSHOT</version>
	</dependency>
</dependencies>
<!-- [...] -->
<repositories>
	<repository>
		<id>snapshots-repository</id>
		<name>Sonatype oss snapshot repo</name>
		<url>https://oss.sonatype.org/content/repositories/snapshots</url>
	</repository>
</repositories>

Snapshots when using a central company repository

Some companies use a central nexus repository that works as a cache, so that all artifacts are downloaded from this repository to accelerate artifact download. Usually, you will find the following configuration in settings.xml :

<settings>
       <mirrors>
               <mirror>
                       <id>internal-repo</id>
                       <name>Maven 2 Repository</name>
                       <url>http://maven.mycompany.com/content/groups/mycompany</url>
                       <mirrorOf>*</mirrorOf>
               </mirror>
       </mirrors>
<!-- ... -->
</settings>

If you don't have access to the configuration of this repository to add AndroidAnnotations' repository, or if it takes time, don't panic, and change your settings.xml to match the following configuration :

<settings>
       <mirrors>
               <mirror>
                       <id>internal-repo</id>
                       <name>Maven 2 Repository</name>
                       <url>http://maven.mycompany.com/content/groups/mycompany</url>
                       <mirrorOf>*,!snapshots-repository</mirrorOf>
               </mirror>
       </mirrors>
       <profiles>
               <profile>
                       <id>AndroidAnnotationsRepository</id>
                       <activation>
                               <activeByDefault>true</activeByDefault>
                       </activation>
                       <repositories>
                               <repository>
                                       <id>snapshots-repository</id>
                                       <name>Sonatype oss snapshot repo</name>
                                       <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                               </repository>
                       </repositories>
               </profile>
       </profiles>
</settings>

The key setting here is <mirrorOf>*,!snapshots-repository</mirrorOf>, it says : "download everything from the central repository, except artifacts coming from the AndroidAnnotations repository".

⚠️ **GitHub.com Fallback** ⚠️