Gradle构建不会下载依赖项

zer*_*pha 15 java spring gradle

gradle build我的Web应用程序的根目录中运行后,声明的spring安全性依赖项build.gradle不会被下载.

这是我的 build.gradle

/*
 * This build file was auto generated by running the Gradle 'init' task
 * by 'hombod' at '7/19/16 4:19 PM' with Gradle 2.14.1
 *
 * This generated file contains a commented-out sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.14.1/userguide/tutorial_java_projects.html
 */


// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.21'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'

    compile 'org.springframework.security:spring-security-web:4.1.1.RELEASE'
}
Run Code Online (Sandbox Code Playgroud)

相反,我只是得到这个消息

:compileJava UP-TO-DAT
:processResources UP-T
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO
:processTestResources
:testClasses UP-TO-DAT
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
Run Code Online (Sandbox Code Playgroud)

这是我运行gradle init命令的spring mvc web应用程序

JBi*_*gas 30

系统缓存从属jar,因此不会一次又一次地下载.

如果您的目标只是查看依赖项的下载,那么您可以强制重新下载.

删除本地存储的所有依赖缓存[1]

$ rm -rf ~/.gradle/caches/
Run Code Online (Sandbox Code Playgroud)

然后重启你的构建

$ gradlew clean build
Run Code Online (Sandbox Code Playgroud)

您还可以使用[2]强制执行依赖项更新

$ gradlew --refresh-dependencies
Run Code Online (Sandbox Code Playgroud)

[1] https://docs.gradle.org/current/userguide/dependency_management.html#sec:dependency_cache
[2] https://docs.gradle.org/current/userguide/dependency_management.html#sub:cache_refresh


Art*_*nev 7

在我的情况下有帮助的解决方案:

File -> Invalidate Caches/Restart...
Run Code Online (Sandbox Code Playgroud)

  • 也许值得一提的是,这个答案假设您使用的是 Intellij 或其他缓存您的依赖项的 IDE。也就是说,这对我有用。 (3认同)

Jom*_*n68 5

我正在使用 IntelliJ 2018.2.3,Gradle 没有为我下载依赖项。

我发现我必须取消选中 Gradle 设置中的“离线工作”框才能让它下载它们。我不确定这个框是如何被选中的,因为我没有检查它(诚实)。

编辑:在 IntelliJ 2021.2.1 中,现在可以在 Gradle 工具窗口中切换离线模式,如下所示:

在此输入图像描述