简体   繁体   English

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

[英]Maven refuse to download aar packaged dependency from remote repository

I want to use this android dependency in my java program: 我想在我的java程序中使用这个android依赖项:

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

so I added all the plugins & repositories into my maven pom file: 所以我将所有插件和存储库添加到我的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>
        ...

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: 但没有任何反应,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 [错误] /home/peng/git-drone/dronespike/src/main/scala/Main.scala:1:object o3dr不是包com的成员
[ERROR] import com.o3dr.android._ [错误]导入com.o3dr.android._
[ERROR] ^ [错误] ^

Question : What should I do to fix this problem? 问题 :我该怎么做才能解决这个问题?

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. 根据您的maven版本的要求,根据我之前面临的情况,您可能需要添加发布和快照的配置。 In my case, I was just able to get the lib once I specified these parameters: 在我的情况下,一旦我指定了这些参数,我就能够获得lib:

<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. 没有它,没有下载依赖项。

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

If Maven couldn't download the artifact, it would complain much sooner in the build lifecycle. 如果Maven无法下载工件,那么在构建生命周期中它会更快地抱怨。 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. aar不是标准的Maven工件,因此Maven不知道如何处理它。 Using it requires a third party plugin with extensions, hence usage of android-maven-plugin . 使用它需要第三方插件扩展,因此使用android-maven-plugin Reading its documentation , it has some requirements to work properly. 阅读其文档 ,它有一些正常工作的要求。 Specifically you didn't use android packaging as mentioned here: 具体来说,你没有使用这里提到的android包装:

usage of a supported packaging: apk, aar or apklib 支持包装的使用:apk,aar或apklib

Indeed, looking at the plugin source code it checks for android packaging before adding anything from aar to classpath. 实际上,在查看插件源代码之前,它会在从aar添加到classpath之前检查android包装。

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: 查看依赖项可用的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>

And indeed the effective target file is available via the URL: 实际上,有效的目标文件可以通过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). 其中尊重存储库URL及其Maven坐标(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. 另请注意:不要重复使用存储库ID central ,除非出于特定原因,否则您将覆盖Maven构建的中央(默认)存储库,并且所有依赖项(和插件)仅由新推出的依赖项(和插件)获取。

sbt-android can handle this configuration. sbt-android可以处理这个配置。

build.sbt build.sbt

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

project/plugins.sbt 项目/ plugins.sbt

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

Add publishing and resolver rules as necessary. 根据需要添加发布和解析器规则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven 多模块项目尝试从存储库下载内部依赖项 - Maven multimodule project tries to download inner dependency from repository Maven 无法从本地存储库(nexus)下载某些依赖项或插件 - Maven cannot Download from local repository (nexus) for some dependency or plugins 如何从远程存储库向我的Java项目添加Maven依赖关系? - How to add a Maven dependency from a remote repository to my Java project? 从远程maven存储库下载并执行jar文件 - download and execute jar file from remote maven repository 如何从远程存储库下载maven工件到本地文件夹? - How download maven artifact from remote repository to local folder? Maven为什么要从远程存储库下载模块 - Why does Maven want to download a module from a remote repository Maven查找在远程存储库中特定版本中具有传递依赖项的依赖项 - Maven find dependency having a transitive dependency in a specific version in a remote repository 有什么方法可以从 jitpack 的 maven 依赖项下载 aar - Is there any way to download aar from maven dependencies at jitpack 从远程存储库BitBucket下载依赖项时,Maven生成成功并带有多个警告 - Maven build success with several warnings while downloading dependency from remote repository BitBucket 如何在不手动触摸远程 maven 存储库的情况下更新 pom.xml SNAPSHOT 依赖项版本? - How to update pom.xml SNAPSHOT dependency version from remote maven repository without touching it manually?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM