40

After running gradle build in the root directory of my web app, the spring security dependency declared in build.gradle does not get downloaded.

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

user987339
  • 10,519
  • 8
  • 40
  • 45
secondbreakfast
  • 4,194
  • 5
  • 47
  • 101

6 Answers6

70

System caches the dependent jars so it won't be downloaded again and again.

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]

$ rm -rf ~/.gradle/caches/

Then restart your build

$ gradlew clean build

You could also force a dependency update with [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

JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
17

The solution that helped in my case:

File -> Invalidate Caches/Restart...
Artem Botnev
  • 2,267
  • 1
  • 14
  • 19
  • 5
    Perhaps worth mentioning that this answer assumes you're using Intellij or another IDE which caches your dependencies. That said, this worked for me. – brntsllvn Jan 04 '19 at 21:27
  • Once again this pesky problem has had me regress and look for the problem in Gradle whereas it is an IJ issue. The number of times this has impacted me in development over the years using different tech. stacks is very very annoying. – Beezer Apr 19 '22 at 17:55
5

I'm using IntelliJ 2018.2.3 and Gradle was not downloading dependencies for me.

I found that I had to uncheck the 'Offline work' box in the Gradle settings to get it to download them. 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:

enter image description here

Joman68
  • 2,248
  • 3
  • 34
  • 36
  • 1
    You saved my day. In my case checked 'Toggle Offline Mode' didn't trigger libraries download. After unchecking the button and.. remove cached files from File > Invalidate Caches... resolved the problem. – mazend Oct 08 '21 at 02:15
4

If your project builds successfully some time it may be gradle download problem with a current proxy. Gradle has it's own dependency management system similar to maven. I think parts of the gradle publish plugin are backed by maven in some way (not verified). Regardless you shouldn't have to worry about that level of depth, gradle will handle it. Your problem is setting up the proxy. You just need to set some variables in $projectDir/gradle.properties, for example:

#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.

2

had something like this problem while was building older react-native project.

the react-native run-android command just did print:

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.

but to prevent download of files again and again used GradleCopy to make them available offline and changed the build.gradle file like below:

// 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"
        }
    }
}

(i.e. did set offline variable to my m2repository path and used it like: maven { url uri(offline) })

Top-Master
  • 7,611
  • 5
  • 39
  • 71
1

Choosing a right log level [1] will allow you to see what is happening behind. -i/--info will show you whether gradle has used the cached dependency or the dependency downloaded.

gradle clean build -i
  1. https://docs.gradle.org/current/userguide/logging.html#sec:choosing_a_log_level
Prabah
  • 807
  • 6
  • 12