Including dagger generated sources in an apklib

453 Views Asked by At

I have a mavenized apklib which uses dagger (1.1.0) internally. The maven build generates the annotations folder inside the build output folder with the appropriate adapter classes. However, these are not included in the generated apklib.

What's the correct configuration for the build process to include the generated sources inside the apklib?

I'm using maven v3.0.4, android-maven-plugin v3.6.0 and the maven-compiler-plugin v3.1

Edit: Here's my pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xxx</groupId>
    <artifactId>yyy</artifactId>
    <version>0.0.1</version>
    <packaging>apklib</packaging>

    <properties>
        <maven.build.timestamp.format>yyMMdddHHmm</maven.build.timestamp.format>
        <android.version>4.3</android.version>
        <versionCode>${maven.build.timestamp}</versionCode>
        <android.sdk.platform>18</android.sdk.platform>
    </properties>

    <dependencies>
        <!-- Other dependencies... -->
        <dependency>
            <groupId>com.squareup.dagger</groupId>
            <artifactId>dagger</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.dagger</groupId>
            <artifactId>dagger-compiler</artifactId>
            <version>1.1.0</version>
            <optional>true</optional>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.6.0</version>
                <dependencies>
                    <dependency>
                        <groupId>com.squareup.dagger</groupId>
                        <artifactId>dagger-compiler</artifactId>
                        <version>1.1.0</version>
                    </dependency>
                </dependencies>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
1

There are 1 best solutions below

2
On

Just use maven-resources-plugin to copy the generated source where you want. "directory" is the source directory, in your target/... you shoud modify the "phase" to a post source generation phase like "prepare-package".

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
  <execution>
    <id>copy-resources1</id>
    <phase>process-resources</phase>
    <goals>
      <goal>copy-resources</goal>
    </goals>
    <configuration>
      <encoding>UTF-8</encoding>
      <outputDirectory>${project.build.directory}/...</outputDirectory>
      <resources>
        <resource>
          <directory>${project.build.directory}/...</directory><!-- source dir-->
          <include>**/*</include>
        </resource>
      </resources>
    </configuration>
  </execution>
</executions>
</plugin>