32

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"
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
greeble31
  • 4,894
  • 2
  • 16
  • 30

1 Answers1

61

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.

Community
  • 1
  • 1
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841