Java Gradle build不';t下载依赖项

Java Gradle build不';t下载依赖项,java,spring,gradle,Java,Spring,Gradle,在my my web app的根目录中运行gradle build后,不会下载build.gradle中声明的spring安全依赖项 这是我的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

在my my web app的根目录中运行
gradle build
后,不会下载
build.gradle
中声明的spring安全依赖项

这是我的
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'
}
相反,我只是得到了这个信息

: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

这是一个spring mvc web应用程序,我在

系统中运行了
gradle init
命令,它缓存了依赖的JAR,因此不会一次又一次地下载它

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

删除本地存储的任何依赖项缓存[1]

$ rm -rf ~/.gradle/caches/
然后重新启动构建

$ gradlew clean build
您还可以使用[2]强制进行依赖项更新

$ gradlew --refresh-dependencies
[1]

[2]

如果您的项目在某个时间成功构建,则当前代理可能存在严重的下载问题。 Gradle有自己的依赖管理系统,类似于maven。我认为GradlePublish插件的某些部分在某种程度上得到了maven的支持(未经验证)。不管怎样,你不必担心深度,格拉德尔会处理好的。您的问题是设置代理。您只需要在$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

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

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

react native run android
命令刚刚打印:

Could not find com.android.tools.build:gradle:2.3.3
在对
build.gradle
文件进行了大量更改后,发现它是正常的 刚刚在
android Studio
中打开了我的
react native
项目的
android
目录,所有依赖项都已下载

但是为了防止一次又一次地下载文件,我们将其用于脱机使用,并更改了
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
变量设置为我的
m2存储库
路径,并像这样使用它:
maven{url uri(offline)}

在我的案例中有帮助的解决方案:

File -> Invalidate Caches/Restart...

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


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

它已经下载了。检查相关文件夹。@天行者,但我在我的web应用程序的任何地方都看不到它,@iMassakre“看不见”==无法在代码中引用它?@iMassakre您使用什么IDE,如果有的话?你有编译时或运行时错误吗?@yonisha我正在使用Eclipse。没有编译或运行时错误。我只是想为我的web应用下载spring security。也许值得一提的是,这个答案假设您使用的是Intellij或另一个缓存依赖项的IDE。也就是说,这对我很有效。