javaintellij-ideaspark-javaintellij-13

IntelliJ cannot resolve symbol 'spark' when importing Spark Java


I am currently running the latest IntelliJ and I am trying to use SparkJava Webserver for a Gradle project I'm writing. When I do compile and run with gradle everything works fine, however I am getting an error in

import static spark.Spark.*;

Where IntelliJ cannot resolve the symbol spark, even though I obviously have the correct dependency set in my build.gradle:

    plugins {
    id 'java'
}

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

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
    implementation 'mysql:mysql-connector-java:8.0.27'
    implementation "com.sparkjava:spark-core:2.9.3"
    implementation "org.slf4j:slf4j-simple:1.7.9"

}

test {
    useJUnitPlatform()
}

Is there any way to circumvent this?

Many thanks in advance.


Solution

  • I got it:

    In IntelliJ, under View -> Tool Windows -> Gradle there's an option to refresh everything Gradle related at the following button: enter image description here

    Using this refreshes the cache and yields the correctly imported dependency.