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

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

问题描述



使用gradle,我没有成功将Amazon依赖项添加到提供的作用域中< 因为他们需要


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


亚马逊支持提供的解决方案中没有一个适合我。



如果某人成功使用了亚马逊地图或使用Gradle的亚马逊消息,请在此分享您的build.gradle文件。

解决方案

Gradle的2.12版本中,compileOnly 被添加以提供与提供的范围类似的功能。测试类路径中会发生什么不同。这里是相关的引用和摘录:


现在可以声明依赖关系,只在编译时使用,一个href =https://docs.gradle.org/2.12/userguide/java_plugin.html> Java插件。仅编译依赖关系仅在源编译期间使用,并且不包含在运行时类路径中或暴露于依赖项目中。这种行为与基于Maven的构建中提供的'provided'范围类似。但是,与Maven提供的依赖关系不同,仅在Gradle中编译依赖关系不包含在测试类路径中。



仅应编译相关源代码集的compileOnly配置

 依赖关系{
compileOnly'javax.servlet:servlet-api:2.5'
}



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

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

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.

None of the solutions provided by Amazon support worked for me.

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

解决方案

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:

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.

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天全站免登陆