Gradle build不会下载依赖项

时间:2016-07-20 16:20:43

标签: java spring gradle

在我的网络应用程序的根目录中运行build.gradle后,build.gradle中声明的spring安全依赖关系无法下载。

这是我的/* * 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' }

: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

相反,我只收到此消息

gradle init

这是我在

中运行tcpdump命令的spring mvc web应用程序

5 个答案:

答案 0 :(得分:21)

系统缓存相关的罐子,因此不会一次又一次地下载。

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

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

$ rm -rf ~/.gradle/caches/

然后重启你的构建

$ gradlew clean build

您还可以使用[2]

强制执行依赖项更新
$ gradlew --refresh-dependencies

[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

答案 1 :(得分:5)

对我来说有帮助的解决方案:

File -> Invalidate Caches/Restart...

答案 2 :(得分:2)

如果您的项目成功构建了一段时间,则可能是当前代理的gradle下载问题。 Gradle有自己的依赖管理系统,类似于maven。我认为gradle publish插件的一部分以某种方式得到了maven的支持(未经验证)。不管您不必担心那种深度,gradle都可以解决。您的问题是设置代理。您只需要在$ projectDir / gradle.properties中设置一些变量,例如:

#http proxy setup
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

这可用于下载不带代理的依赖项。如果要使用代理,则可以使用下面的代码代替上面的代码。

systemProp.https.proxyPort=3128
systemProp.http.proxyHost=192.168.16.2
systemProp.https.proxyHost=192.168.16.2
systemProp.http.proxyPort=3128

可以根据需要更改代理端口和主机。

答案 3 :(得分:1)

在构建旧的react-native项目时遇到了类似的问题。

react-native run-android命令刚刚完成打印:

Could not find com.android.tools.build:gradle:2.3.3
在对build.gradle文件进行了大量更改后,

可以,并且 刚刚在android中打开了react-native项目的Android-Studio目录,并且所有依赖项都已下载。

但为防止文件一次又一次下载,使用GradleCopy使文件脱机可用,并更改了build.gradle文件,如下所示:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        //kotlin_version = '1.2.40'
        offline = 'D:/android/sdk/extras/m2repository'
    }
    repositories {
        try { maven { url uri(offline) } } catch (Throwable e) {}
        try { maven { url uri('C:/Program Files/Android/Android Studio/gradle/m2repository') } } catch (Throwable e) {}

        jcenter()
        maven { url 'https://maven.google.com' }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3' //was "2.3.3" with "gradle-3.4.1-all.zip" got "3.1.3" with "gradle-4.4-all.zip"
        ////below "kotlin" is required in root "build.gradle" else the "offline" repo will not get searched
        //classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        try { maven { url uri(offline) } } catch (Throwable e) {}

        jcenter()
        mavenLocal()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        mavenCentral()

        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

(即确实将offline变量设置为我的m2repository路径,并像maven { url uri(offline) }那样使用它

答案 4 :(得分:1)

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

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