Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method compile() for arguments [com.sparkjava:spark-core:2.9.3] on object of type org.gradle.api.internal.artifacts.dsl

Tags:

spark-java

I am trying to learn spark java web framework. I am using Intellij and created a new project just added a HelloWorld class, but got this error,

Build file '/Users/mingwang/SourceCodes/spark-example/build.gradle' line: 17

A problem occurred evaluating root project 'spark-example'.
> Could not find method compile() for arguments [com.sparkjava:spark-core:2.9.3] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

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

My build.gradle is like

plugins {
    id 'java'
    id 'application'
    id 'com.github.johnrengelman.shadow' version '7.0.0'
}

group 'org.example'
version '1.0-SNAPSHOT'

mainClassName = "HelloWorld"

repositories {
    mavenCentral()
}

dependencies {
    compile "com.sparkjava:spark-core:2.9.3"
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

test {
    useJUnitPlatform()
}

can anyone help me with it? Thanks.

like image 772
Woo Lee Avatar asked May 03 '21 09:05

Woo Lee


People also ask

Could not find method implementation() for arguments in Gradle?

Method 1: Update to the latest Gradle version In case you are using the “implementation” configuration in an older version of Gradle, the Gradle will not recognize it and throw this error. Hence updating Gradle and Gradle build plugin to the latest version can help solve this issue.

Could not find method compile () for arguments react native?

You can fix this issue by replacing compile with implementation in node_modules/react-native-geocoder/android/build. gradle.

What is CompileOnly in gradle?

compileOnly dependencies are available while compiling but not when running them. This is equivalent to the provided scope in maven. It means that everyone who wants to execute it needs to supply a library with all classes of the CompileOnly library.

What is difference between compile and implementation in gradle?

Gradle dependency configuration compile -> apiapi keyword is the same as deprecated compile which expose this dependency for all levels. compile -> implementation Is preferable way because has some advantages. implementation expose dependency only for one level up at build time (the dependency is available at runtime).

Why can't I run Gradle tests with Java plugin?

The reason for failure is compile is that the compile, runtime, testCompile, and testRuntime configurations introduced by the Java plugin have been deprecated since Gradle 4.10, and were finally removed in Gradle 7.0. So, to solve the problem I had to install the lower version of gradle.

What is the Gradle exception when implementation is not recognized?

Learn how to solve the Gradle exception when implementation is not recognized. The implementation instruction is a dependency configuration that is used for library declaration. It was introduced in Gradle 3. So this exception is triggered always when Gradle doesn't recognize the implementation instruction.

How to include dependencies in a Gradle project?

After updating the classpath, navigate to your App, then Gradle Scripts and select the gradle-wrapper.properties file and update the distributionUrl to the latest version of Gradle: After this change you will need to synchronize your project and you should be able to include dependencies using the implementation instruction.

How to replace compile dependencies with implementation dependencies in a build?

In dependencies {} closure in your build file, you have some compile dependencies like 'javax.cache','javax.servlet' . Replace them from being compile dependencies to be implementation dependencies. In other words, replace the word compile at the starting of all such dependencies with the word 'implementation'


Video Answer


1 Answers

The compile statement is deprecated and has been removed in Gradle 7.0. You should use implementation or api instead. The differences are explained in this answer.

In your build.gradle, replace

compile "com.sparkjava:spark-core:2.9.3"

with

implementation "com.sparkjava:spark-core:2.9.3"
like image 114
Lemon Avatar answered Oct 20 '22 04:10

Lemon