Maven - PerfectCarl/androidannotations GitHub Wiki

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

Please first read the GettingStarted 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>3.0</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>androidannotations-api</artifactId>
		<version>3.0</version>
	</dependency>
</dependencies>

Make sure your project is built with Java 1.6:

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

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>3.1-SNAPSHOT</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.androidannotations</groupId>
		<artifactId>androidannotations-api</artifactId>
		<version>3.1-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** ⚠️