如何在 Gradle 构建中使用提供的 jar 文件范围? [英] How to use provided scope for jar file in Gradle build?

查看:33
本文介绍了如何在 Gradle 构建中使用提供的 jar 文件范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用中使用 Amazon Maps 和 Amazon Messaging.

I need to use Amazon Maps and Amazon Messaging in my apps.

使用 gradle,我没有成功添加具有提供"范围的 Amazon 依赖项因为他们需要成为 :

With gradle, I did not succeed in adding the Amazon dependencies with a "provided" scope as they need to be :

JAR 文件包含 Amazon Maps API 的存根实现.它不包含 Maps API 类的实际实现,因此您不应将 JAR 编译到您的应用中.

The JAR file contains stub implementations of the Amazon Maps API. It does not contain actual implementations of the Maps API classes, so you should not compile the JAR into your app.

亚马逊支持提供的所有解决方案均不适合我.

如果有人成功通过 Gradle 使用亚马逊地图或亚马逊消息传递,请在此处分享您的 build.gradle 文件.

If someone succeeded to use amazon maps or amazon messaging with Gradle, please share your build.gradle file here.

推荐答案

2.12 版本的 Gradle 中,compileOnly添加 以提供与 provided 范围类似的功能.测试类路径中发生的事情有所不同.以下是发行说明中的​​相关引述和片段:

In the 2.12 release of Gradle, compileOnly was added to give similar functionality to provided scope. There is a difference in what happens in the test classpath. Here is relevant quote and snippet from the release notes:

您现在可以将依赖项声明为仅在编译时与 Java 插件结合使用.仅编译依赖项仅在源代码编译期间使用,不包含在运行时类路径中或暴露给依赖项目.此行为类似于基于 Maven 的构建中可用的提供"范围的行为.但是,与 Maven 提供的依赖项不同,仅编译 Gradle 中的依赖项不会包含在测试类路径中.

You can now declare dependencies to be used only at compile time in conjunction with the Java plugin. Compile only dependencies are used only during source compilation and are not included in the runtime classpath or exposed to dependent projects. This behavior is similar to that of the 'provided' scope available in Maven based builds. However, unlike Maven provided dependencies, compile only dependencies in Gradle are not included on the test classpath.

应将仅编译依赖项分配给相关源集的compileOnly"配置.

Compile only dependencies should be assigned to the relevant source set's 'compileOnly' configuration.

dependencies {
    compileOnly 'javax.servlet:servlet-api:2.5'
}

这篇关于如何在 Gradle 构建中使用提供的 jar 文件范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆