为什么"Graping 4.4/Java插件"中没有"api"方法,"实现"是什么时候?

gre*_*e31 15 java android gradle android-studio build.gradle

我正在使用AS 3.1,试图成为一名优秀的程序员并清除"编译已过时"的警告.但是我希望这个特殊的.jar将Guava暴露为API.其他项目(例如CloudServerApplication)也需要Guava.但是,当我使用api关键字而不是compile或implementation,我得到这个:

>gradlew FrameManager:build

> Configure project :CloudServerApplication
4.4

> Configure project :FrameManager
4.4


FAILURE: Build failed with an exception.

* Where:
Build file 'C:\FrameManager\app\build.gradle' line: 16

* What went wrong:
A problem occurred evaluating project ':FrameManager'.
> Could not find method api() for arguments [com.google.guava:guava:14+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Run Code Online (Sandbox Code Playgroud)

我试过谷歌搜索错误,但没有找到任何有用的东西.不确定下一步该去哪儿.

我的build.gradle:

apply plugin: 'java'

println GradleVersion.current().getVersion()

repositories {
    jcenter()
}

dependencies {
    implementation 'org.json:json:20160212'
    api 'com.google.guava:guava:14+'   //<-- This used to be "compile"
}
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 26

无法为参数找到方法api()

该java插件不包含此方法.

你必须使用这个插件:

apply plugin: 'java-library'
Run Code Online (Sandbox Code Playgroud)

您可以查看官方文档:

标准Java插件和Java Library插件之间的主要区别在于后者引入了向消费者公开的API的概念.库是一个Java组件,旨在供其他组件使用.这是多项目构建中非常常见的用例,但只要您有外部依赖项.

该插件公开了两种可用于声明依赖关系的配置:api和实现.