我使用Maven,我需要处理其他依赖项中的类。在处理这些类之前,maven-dependency-plugin
将其与unpack-dependencies
目标一起解压缩这些依赖项,以便随后可以在target
目录中处理这些类。将引用的依赖项打包为JAR时,一切都很好。现在,我面临着需要以特殊方式进行类处理的AAR依赖关系。到目前为止,我得到的错误是:
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]
该aars-only
执行标识符来自下面的配置,但在总体上给出了同样的错误,如果不分裂的执行。这是我的maven-dependency-plugin
配置,稍后将其分为两个执行:
<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>
注释掉aars-only
执行会导致运行时应用程序崩溃,但是构建会通过,因为jars-only
执行jar
仅包括类型-不完全是我需要的类型。
如何将AAR依赖项(baz-group
)解压缩到target/classes
目录中?是否可以以maven-dependency-plugin
某种方式进行配置,使其可以接受AAR及其打包classes.jar
?还是有其他方法可以使其仅使用另一个插件就可以工作?
(也许这是一个有用的提示:我也使用com.simpligility.maven.plugins:android-maven-plugin
。)
MDP插件似乎无法与此直接配合使用。
如该线程中所指出的-如何将AAR转换为JAR,AAR本质上是一个包含其他归档信息的zip。
我可以在这里看到2种可能的方法。
1)-使用ANT解压缩AAR,找到其中包含的jar文件,然后也使用ANT解压缩。
2)-与以前一样,使用ANT解压缩AAR,然后将其复制到中间文件夹,然后使用maven-dependency-plugin解压缩jar。
https://maven.apache.org/guides/mini/guide-using-ant.html
我无法对此进行测试,但是此POM片段可能用作起点。
<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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句