admin管理员组

文章数量:1406943

I am currently trying to work on my Spring Boot Java Application (Gradle) but IntelliJ (2024.3.4.1) just won't let me work properly. I don't know if I am missing something out but its behavior annoys me and I don't want to give in and let the IDE win with its idea.

So the issue is that I literally specify the dependencies in my gradle file. I have the Spring Boot web and test dependencies but still can't use these components in my code, examples:

  • @SpringBootTest
  • MockMvc

However, the IDE does suggest that I add it to the class path. But I don't want that. In all my projects which partially were gradle, it has NEVER asked me to do that before and no tutorial suggests me to add them to the class path as IntelliJ wants. When I actually add them, the dependencies work magically.

Am I just doing something wrong? I got quite frustrated trying to get the IDE work as it always does and not even coming to coding after an hour.

And yes, I have deleted the project once and newly cloned it as well as tried to invalidate the caches.

My Gradle:

plugins {
    java
    id(".springframework.boot") version "3.4.2"
    id("io.spring.dependency-management") version "1.1.7"
}

group = "x"
version = "x"

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(23)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    // Spring Boot
    implementation(".springframework.boot:spring-boot-starter-web")
    implementation(".springframework.boot:spring-boot-starter-aop")
    implementation("jakarta.servlet:jakarta.servlet-api:6.0.0")

    // Spring Test
    developmentOnly(".springframework.boot:spring-boot-devtools")
    testImplementation(".springframework.boot:spring-boot-starter-test") {
        exclude(group = ".junit.vintage", module = "junit-vintage-engine")
    }
    compileOnly(".jetbrains:annotations:26.0.2")

    // Database
    runtimeOnly(".postgresql:postgresql")

    // JWT
    implementation("io.jsonwebtoken:jjwt-api:0.12.6")
    runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.6")
    runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.6")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

本文标签: javaIntelliJ only accepts class path dependencies instead of gradle dependenciesStack Overflow