问题
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
.)
回答1:
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>
来源:https://stackoverflow.com/questions/33940455/how-do-i-unpack-aar-dependency-classes-in-maven