How do I unpack AAR dependency classes in Maven?

Lyubomyr Shaydariv

I use Maven and I need to process classes from another dependencies. Before processing the classes, maven-dependency-plugin is used to unpack those dependencies with the unpack-dependencies goal, so then I can process the classes in the target directory. Everything is fine while the referenced dependencies are packaged as JARs. Now I'm faced with an AAR dependency that is required to be class-processed in a special way. The error I get so far is:

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack-dependencies (aars-only) on project app-android: Unknown archiver type: No such archiver: 'aar'. -> [Help 1]

The aars-only execution identifier comes from the configuration below, but in general it gives the same error if not splitting the executions. Here is my maven-dependency-plugin configuration I have split later into two executions:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>jars-only</id>
            <phase>process-classes</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeScope>runtime</includeScope>
                <includeGroupIds>foo-group,bar-group</includeGroupIds>
                <includeTypes>jar</includeTypes> <!-- this is necessary to skip AAR dependencies -->
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
            </configuration>
        </execution>
        <execution>
            <id>aars-only</id>
            <phase>process-classes</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeScope>runtime</includeScope>
                <includeGroupIds>baz-group</includeGroupIds>
                <includeTypes>aar</includeTypes> <!-- hoping this can process AARs as well, but it's just another execution, nothing special -->
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Commenting out the aars-only execution leads to a runtime application crash, but the build passes as the jars-only execution includes the jar type only -- not exactly what I need.

How do I unpack the AAR dependency (baz-group) to the target/classes directory? Is it possible to configure the maven-dependency-plugin somehow so it could accept AAR and its packed classes.jar? Or is there any other way to make it work probably just using another plugin?

(Maybe it's a useful hint: I also use com.simpligility.maven.plugins:android-maven-plugin.)

Alex

It looks as though the MDP plugin won't work with this directly.

As pointed out in this thread - How to convert AAR to JAR, the AAR is essentially a zip with other archive information in it.

There are 2 possible approaches I can see here.

1) - Use ANT to unzip the AAR, find the jar file contained in it, then unzip with ANT as well.

2) - Use ANT to unzip the AAR as before, then copy it to an intermediate folder, and use the maven-dependency-plugin to unpack the jar.

https://maven.apache.org/guides/mini/guide-using-ant.html

I'm not able to test this, but this POM snippet might be of use as a starting point.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
    <execution>
        <id>prepare</id>
        <phase>build</phase>
        <configuration>
            <tasks>
                <unzip src="source/my_archive.aar" dest="output/" />
                <copy file="output/classes.jar" tofile="my_archive.jar"/>

                <!-- 
                     Either extract the jar here, 
                     or place it where the maven dependencies plugin 
                     can find it, and extract it in a later build phase 
                -->
            </tasks>
        </configuration>
        <goals>
            <goal>run</goal>
        </goals>
    </execution>
</executions>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do I add a Maven dependency in Eclipse?

From Java

How do I read a Maven dependency tree

From Dev

How do I inject a dependency into non Controller classes?

From Java

How do I enable index downloads in Eclipse for Maven dependency search?

From Dev

How do I set a Maven dependency version programmatically?

From Java

How do I tell Maven to use the latest version of a dependency?

From Dev

How to unpack just the files from a sub-folder in maven-dependency-plugin with goal unpack-dependencies?

From Dev

Maven dependency works from Maven-local but not when I deploy the aar to repository

From Java

In Maven 2, how do I know from which dependency comes a transitive dependency?

From Java

How can I reference unit test classes of a maven dependency in my java project?

From Dev

How do I upload an aar library to Nexus?

From Dev

How do I unpack a single git object?

From Dev

How do I unpack tuple format in R?

From Dev

Can an Android AAR have a dependency on another AAR when built with Maven?

From Dev

Maven unpack-dependencies of a plugin dependency

From Dev

maven-dependency-plugin:unpack Error

From Dev

How can I build an .aar library with shrunk classes in Android Studio?

From Java

How do I replace a dependency of a dependency in gradle?

From Dev

How do I get the maven dependency:tree command to show when I'm using a RELEASE version?

From Java

How do you replace the class of a Maven dependency?

From Java

How can I add JDT as a Maven dependency?

From Dev

How can I add LIRE dependency to Maven?

From Dev

[Laravel]: How do I dependency inject into an abstract class extended by other classes(jobs)

From Dev

How do I access Cofoundry settings and other dependency injected classes in theme views

From Dev

How to generate QDomain file using entity classes in maven dependency?

From Java

How do I include a dependency's test jar into a Maven project's deployment?

From Java

How do I know which maven dependency should be add to pom.xml

From Java

Why should I include a gradle dependency as `@aar`

From Java

Exclude classes from a dependency in Maven

Related Related

  1. 1

    How do I add a Maven dependency in Eclipse?

  2. 2

    How do I read a Maven dependency tree

  3. 3

    How do I inject a dependency into non Controller classes?

  4. 4

    How do I enable index downloads in Eclipse for Maven dependency search?

  5. 5

    How do I set a Maven dependency version programmatically?

  6. 6

    How do I tell Maven to use the latest version of a dependency?

  7. 7

    How to unpack just the files from a sub-folder in maven-dependency-plugin with goal unpack-dependencies?

  8. 8

    Maven dependency works from Maven-local but not when I deploy the aar to repository

  9. 9

    In Maven 2, how do I know from which dependency comes a transitive dependency?

  10. 10

    How can I reference unit test classes of a maven dependency in my java project?

  11. 11

    How do I upload an aar library to Nexus?

  12. 12

    How do I unpack a single git object?

  13. 13

    How do I unpack tuple format in R?

  14. 14

    Can an Android AAR have a dependency on another AAR when built with Maven?

  15. 15

    Maven unpack-dependencies of a plugin dependency

  16. 16

    maven-dependency-plugin:unpack Error

  17. 17

    How can I build an .aar library with shrunk classes in Android Studio?

  18. 18

    How do I replace a dependency of a dependency in gradle?

  19. 19

    How do I get the maven dependency:tree command to show when I'm using a RELEASE version?

  20. 20

    How do you replace the class of a Maven dependency?

  21. 21

    How can I add JDT as a Maven dependency?

  22. 22

    How can I add LIRE dependency to Maven?

  23. 23

    [Laravel]: How do I dependency inject into an abstract class extended by other classes(jobs)

  24. 24

    How do I access Cofoundry settings and other dependency injected classes in theme views

  25. 25

    How to generate QDomain file using entity classes in maven dependency?

  26. 26

    How do I include a dependency's test jar into a Maven project's deployment?

  27. 27

    How do I know which maven dependency should be add to pom.xml

  28. 28

    Why should I include a gradle dependency as `@aar`

  29. 29

    Exclude classes from a dependency in Maven

HotTag

Archive