Gradle – Could not find method compileOnly

Git clone a new project, Gradle build and hits the following error message :

Terminal

$ gradle clean build

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/mkyong/Documents/workspace/hc2/web/build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':web'.
> Could not find method compileOnly() for arguments [org.springframework.boot:spring-boot-starter-tomcat] on project ':web'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Using Gradle 2.4

Terminal

gradle -version

------------------------------------------------------------
Gradle 2.4
------------------------------------------------------------

Build time:   2015-05-05 08:09:24 UTC
Build number: none
Revision:     5c9c3bc20ca1c281ac7972643f1e2d190f2c943c

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM:          1.8.0_74 (Oracle Corporation 25.74-b02)
OS:           Mac OS X 10.12.6 x86_64

Solution

The scope compileOnly has been introduced since Gradle 2.12, to fix it, just upgrade Gradle to the latest version, like Gradle 4.1 which released on Aug 07, 2017.

References

  1. Gradle blog – Introducing Compile-Only Dependencies
  2. Gradle release

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
asf
Guest
asf

gg, eclipse gradle wrapper was using 2.12 so it couldnt interpret it.
Best wrapper.