Maven 拒绝从远程存储库下载 aar 打包的依赖项

Maven refuse to download aar packaged dependency from remote repository

我想在我的 java 程序中使用这个 android 依赖项:

http://jcenter.bintray.com/com/o3dr/android/dronekit-android/2.9.0/

所以我将所有插件和存储库添加到我的 maven pom 文件中:

<repositories>
    <repository>
        <id>central</id>
        <name>bintray</name>
        <url>http://jcenter.bintray.com</url>
        <!--<snapshots>-->
            <!--<enabled>false</enabled>-->
        <!--</snapshots>-->
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <!--<snapshots>-->
            <!--<enabled>false</enabled>-->
        <!--</snapshots>-->
        <id>central</id>
        <name>bintray-plugins</name>
        <url>http://jcenter.bintray.com</url>
    </pluginRepository>
</pluginRepositories>

<build>
    <plugins>
        <plugin>
            <groupId>com.simpligility.maven.plugins</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>4.1.0</version>

            <extensions>true</extensions>
            <configuration>
                <sign>
                    <debug>false</debug>
                </sign>
            </configuration>
        </plugin>
        ...

然后我将依赖项添加到同一个文件中:

    <dependency>
        <groupId>com.o3dr.android</groupId>
        <artifactId>dronekit-android</artifactId>
        <version>2.9.0</version>
        <type>aar</type>
    </dependency>

但是没有任何反应,maven 将其忽略,就好像它不存在一样,如果我将其主包导入 scala 文件并使用 mvn clear install -U 构建它,我会收到此错误:

[ERROR] /home/peng/git-drone/dronespike/src/main/scala/Main.scala:1: object o3dr is not a member of package com
[ERROR] import com.o3dr.android._
[ERROR] ^

问题:我应该怎么做才能解决这个问题?

根据你maven版本的要求,根据我之前遇到的情况,你可能需要添加release和snapshot的配置。就我而言,一旦我指定了这些参数,我就能够获得库:

<repositories>
    <repository>
        <id>central</id>
        <name>bintray-plugins</name>
        <url>http://jcenter.bintray.com</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.o3dr.android</groupId>
        <artifactId>dronekit-android</artifactId>
        <version>2.9.0</version>
        <type>aar</type>
    </dependency>
</dependencies>

没有它,没有下载依赖。

查看依赖项可用的 bintray 存储库,并通过其 Set me up 选项检查存储库设置,您的存储库坐标不正确,他们应该是:

<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>bintray-3d-robotics-maven</id>
        <name>bintray</name>
        <url>http://dl.bintray.com/3d-robotics/maven</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>bintray-3d-robotics-maven</id>
        <name>bintray-plugins</name>
        <url>http://dl.bintray.com/3d-robotics/maven</url>
    </pluginRepository>
</pluginRepositories>

实际上有效的目标文件可以通过 URL:

https://dl.bintray.com/3d-robotics/maven/com/o3dr/android/dronekit-android/2.9.0/

它尊重存储库 URL 及其 Maven 坐标(groupId、artifactId、版本)。


另请注意:除非出于特定原因,否则不要重复使用存储库 ID central,否则您将覆盖 Maven 构建的中央(默认)存储库,并且您的所有依赖项(和插件)只会由新声明的获取。

使用Android包装,例如<packaging>apk</packaging>.

如果 Maven 无法下载工件,它会在构建生命周期中更快地抱怨。问题是工件已下载,但未使用。 aar 不是标准的 Maven 工件,因此 Maven 不知道如何处理它。使用它需要带有扩展的第三方插件,因此使用 android-maven-plugin。阅读它的 documentation,它有一些正常工作的要求。具体来说,您没有使用此处提到的 android 包装:

usage of a supported packaging: apk, aar or apklib

确实,查看插件 source code 它会在将 aar 中的任何内容添加到类路径之前检查 android 包装。

sbt-android 可以处理这个配置。

build.sbt

androidBuildJar 
name := "yourproject" 
organization := "yourorganization" 
platformTarget := "android-24"
libraryDependencies +="com.o3dr.android" % "dronekit-android" % "2.9.0"

project/plugins.sbt

addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.7")

根据需要添加发布和解析器规则。