Maven refuse to download aar packaged dependency from remote repository

自闭症网瘾萝莉.ら 提交于 2020-04-28 02:34:26

问题


I want to use this android dependency in my java program:

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

so I added all the plugins & repositories into my maven pom file:

<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>
        ...

Then I add the dependency into the same file:

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

But nothing happens, maven ignore it as if it doesn't exist, if I import its main package in a scala file and build it with mvn clear install -U, I get this error:

[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] ^

Question: What should I do to fix this problem?


回答1:


Use Android packaging, e.g. <packaging>apk</packaging>.

If Maven couldn't download the artifact, it would complain much sooner in the build lifecycle. The problem is that artifact is downloaded, but not used. aar is not a standard Maven artifact, so Maven doesn't know what to do with it. Using it requires a third party plugin with extensions, hence usage of android-maven-plugin. Reading its documentation, it has some requirements to work properly. Specifically you didn't use android packaging as mentioned here:

usage of a supported packaging: apk, aar or apklib

Indeed, looking at the plugin source code it checks for android packaging before adding anything from aar to classpath.




回答2:


Depending on the requirement from your maven version, based on what I faced before, you might have the need to add the configuration for release and snapshot. In my case, I was just able to get the lib once I specified these parameters:

<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>

without it, the dependency was not downloaded.




回答3:


Looking at the bintray repository from where the dependency is available, and check the repository settings via its Set me up option, your repositories coordinates are not correct, they should instead be:

<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>

And indeed the effective target file is available via the URL:

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

Which respects the repository URL plus its Maven coordinates (groupId, artifactId, version).


Also note: do not reuse the repository id central, unless for specific reason, otherwise you would override the central (default) repository of your Maven build and all of your dependencies (and plugins) would only be fetched by the newely declared one.




回答4:


sbt-android can handle this configuration.

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")

Add publishing and resolver rules as necessary.



来源:https://stackoverflow.com/questions/37903371/maven-refuse-to-download-aar-packaged-dependency-from-remote-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!