【问题标题】:How can I add spring-security-dependency with gradle in IntelliJ?如何在 IntelliJ 中使用 gradle 添加 spring-security-dependency?
【发布时间】:2020-09-12 12:48:48
【问题描述】:

我想使用依赖: implementation 'org.springframework.boot:spring-boot-starter-security' 在我的 IntelliJ 项目中,但由于任何原因,它无法解决这种依赖关系。

这些是我的依赖项。相关的是spring-boot-starter-security

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
runtime('org.springframework.boot:spring-boot-devtools')
}

由于某种原因,我在启动引导运行时收到此错误消息:

Error-message when starting boot-run

这里是整个 build.gradle 文件:

    plugins {
    id 'org.springframework.boot' version '2.2.7.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'de.hohenheim'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    runtime('org.springframework.boot:spring-boot-devtools')
}

test {
    useJUnitPlatform()
}

bootRun {
    sourceResources(sourceSets.main)
}

【问题讨论】:

    标签: spring spring-boot gradle spring-security build.gradle


    【解决方案1】:

    您需要重新启用 Gradle 在线模式

    对于最新版本的 IntelliJ IDE,请在此处找到一个选项:

    对于旧版本:

    1. 首选项
    2. 进入构建、执行、部署。
    3. 最后选择 Gradle。
    4. 取消选中离线工作。点击应用然后确定。

    希望这会奏效。

    【讨论】:

      【解决方案2】:

      您似乎在离线模式下运行 Gradle。在该模式下,Gradle 将仅使用其本地缓存。当您向项目添加新依赖项时,Gradle 将无法找到它。要修复此错误,请在 Intellij 中禁用离线模式。

      转到Gradle tool window 并禁用此按钮:

      它应该出现在工具栏中(窗口顶部)。如果它不可见,如下图所示,当您放大窗口或单击工具栏最右侧的两个箭头(标记为蓝色)时,它应该会出现:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-19
        • 1970-01-01
        • 2012-02-03
        • 1970-01-01
        • 2016-04-20
        • 2011-01-14
        • 2018-09-27
        • 1970-01-01
        相关资源
        最近更新 更多