I'm using AS 3.1, trying to be a good programmer and clear the "compile is obsolete" warnings. But I desire this particular .jar to expose Guava as an API. Other projects (e.g. CloudServerApplication) need Guava, too. But when I use the api
keyword, instead of compile
or implementation
, I get this:
>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.
I tried Googling the error, but did not find anything useful. Not really sure where to look next.
My 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"
}
In the first scenario, LibraryD is compiled by using api . If any change is implemented inside LibraryD, gradle needs to recompile LibraryD, LibraryB and all other modules which import LibraryB as any other module might use implementation of LibraryD.
A Dependency represents a dependency on the artifacts from a particular source. A source can be an Ivy module, a Maven POM, another Gradle project, a collection of Files, etc... A source can have zero or more artifacts.
Gradle can only run on Java version 8 or higher. Gradle still supports compiling, testing, generating Javadoc and executing applications for Java 6 and Java 7. Java 5 and below are not supported.
It distinguishes between api and implementation dependencies, offering some key benefits for whoever consumes the library. 1. Gradle dependency configuration basics 2. Benefits of fine-grained classpath control 3. The Java Library Gradle plugin makes this possible 4. Real world example 5. Final thoughts 6. Resources
Note, that unlike public / private variables and methods, api / implementation dependencies are not enforced by the runtime. This is merely a build-time optimization, that allows Gradle to know which modules it needs to recompile when one of the dependencies changes its API.
It is one of the breaking changes coming with Android Gradle plugin 3.0 that Google announced at IO17. The compile configuration is now deprecated and should be replaced by implementation or api
The Java module system supports additional more fine granular encapsulation concepts than Gradle itself currently does. For example, you explicitly need to declare which packages are part of your API and which are only visible inside your module. Some of these capabilities might be added to Gradle itself in future versions.
Could not find method api() for arguments
The java
plugin doesn't contain this method.
You have to use this plugin:
apply plugin: 'java-library'
As you can check in the official doc:
The key difference between the standard Java plugin and the Java Library plugin is that the latter introduces the concept of an API exposed to consumers. A library is a Java component meant to be consumed by other components. It’s a very common use case in multi-project builds, but also as soon as you have external dependencies.
The plugin exposes two configurations that can be used to declare dependencies: api and implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With