简体   繁体   English

Gradle 构建不下载依赖项

[英]Gradle build doesn't download dependencies

After running gradle build in the root directory of my web app, the spring security dependency declared in build.gradle does not get downloaded.在我的 web 应用程序的根目录中运行gradle build后,在build.gradle中声明的 spring 安全依赖项不会被下载。

here is my 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'
}

instead, I just get this message相反,我只是收到此消息

: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

This is a spring mvc web app that I ran the gradle init command in这是我在其中运行gradle init命令的 spring mvc Web 应用程序

System caches the dependent jars so it won't be downloaded again and again.系统缓存了依赖的 jar,因此不会一次又一次地下载。

If your goal is to just see the downloads of the dependencies then you can force it to redownload.如果您的目标只是查看依赖项的下载,那么您可以强制它重新下载。

Remove any dependency caches stored locally [1]删除本地存储的任何依赖项缓存 [1]

$ rm -rf ~/.gradle/caches/

Then restart your build然后重新启动您的构建

$ gradlew clean build

You could also force a dependency update with [2]您还可以使用 [2] 强制更新依赖项

$ gradlew --refresh-dependencies

[1] https://docs.gradle.org/current/userguide/dependency_management.html#sec:dependency_cache [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 [2] https://docs.gradle.org/current/userguide/dependency_management.html#sub:cache_refresh

对我有帮助的解决方案:

File -> Invalidate Caches/Restart...

If your project builds successfully some time it may be gradle download problem with a current proxy.如果您的项目在一段时间内成功构建,则可能是当前代理的 gradle 下载问题。 Gradle has it's own dependency management system similar to maven. Gradle 有自己的依赖管理系统,类似于 maven。 I think parts of the gradle publish plugin are backed by maven in some way (not verified).我认为 gradle 发布插件的某些部分以某种方式得到了 maven 的支持(未验证)。 Regardless you shouldn't have to worry about that level of depth, gradle will handle it.无论您不必担心这种深度,gradle 都会处理它。 Your problem is setting up the proxy.您的问题是设置代理。 You just need to set some variables in $projectDir/gradle.properties, for example:您只需要在 $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

This can be used to download dependencies without proxy.这可用于在没有代理的情况下下载依赖项。 If you want to use a proxy for you can use the code as below instead of above code.如果你想使用代理,你可以使用下面的代码而不是上面的代码。

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

Proxy port and host can be changed as you want.代理端口和主机可以根据需要更改。

I'm using IntelliJ 2018.2.3 and Gradle was not downloading dependencies for me.我正在使用 IntelliJ 2018.2.3 并且 Gradle 没有为我下载依赖项。

I found that I had to uncheck the 'Offline work' box in the Gradle settings to get it to download them.我发现我必须取消选中 Gradle 设置中的“离线工作”框才能下载它们。 I'm not sure how this box became checked because I didn't check it (honest).我不确定这个框是如何被选中的,因为我没有选中它(老实说)。

EDIT : In IntelliJ 2021.2.1 Offline Mode can now be toggled in the Gradle tool window, as shown below:编辑:在 IntelliJ 2021.2.1 离线模式中,现在可以在 Gradle 工具窗口中切换,如下所示:

在此处输入图像描述

had something like this problem while was building older react-native project.在构建较旧的react-native项目时遇到了类似的问题。

the react-native run-android command just did print: react-native run-android命令刚刚打印:

Could not find com.android.tools.build:gradle:2.3.3

after lot of changes to the build.gradle file noticed that it was okay and just opened the android directory of my react-native project in Android-Studio and all dependencies was downloaded.在对build.gradle文件进行大量更改后,发现一切正常,只需在Android-Studio中打开我的react-native项目的android目录,并下载所有依赖项。

but to prevent download of files again and again used GradleCopy to make them available offline and changed the build.gradle file like below:但是为了防止一次又一次地下载文件,使用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"
        }
    }
}

(ie did set offline variable to my m2repository path and used it like: maven { url uri(offline) } ) (即确实将offline变量设置为我的m2repository路径并像这样使用它: maven { url uri(offline) }

Choosing a right log level [1] will allow you to see what is happening behind.选择正确的日志级别 [1] 可以让您看到背后发生的事情。 -i/--info will show you whether gradle has used the cached dependency or the dependency downloaded. -i/--info 将显示 gradle 是否使用了缓存的依赖项或下载的依赖项。

gradle clean build -i
  1. https://docs.gradle.org/current/userguide/logging.html#sec:choosing_a_log_level https://docs.gradle.org/current/userguide/logging.html#sec:choosing_a_log_level

regardless of what I tried, the only thing that corrected was shutting down the local server, exit the ide and then restart. 无论我尝试了什么,唯一纠正的方法是关闭本地服务器,退出ide,然后重新启动。 This is NetBeans IDE 8.2. 这是NetBeans IDE 8.2。 Was making me crazy. 让我发疯。 Using command line or plugin. 使用命令行或插件。 None of what I thought would have corrected it did. 我认为没有任何一项可以纠正它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM