Question

I am very new with Gradle and I would like to download all my test dependencies using Gradle. I used gradle init to generate my build file, and copied some dependencis from my previous scripts. However upon using gradle --refresh-dependencies in the project root, the test dependencies still do not download.

I tried searching for answers as to why this happens, but they don't seem to fix my issue. Is there something wrong with my build file?

Particularly, I am after downloading mockito and hamcrest below.

build file:

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.5'

    testCompile "junit:junit:4.11"
    testCompile "org.mockito:mockito-core:1.9.5"
    testCompile "org.hamcrest:hamcrest-library:1.3"
}

test {
  testLogging {
    events 'started', 'passed'
  }
}

task wrapper(type: Wrapper) { gradleVersion = '1.11' }

I am also using Eclipse if that helps.

EDIT: After adding the Gradle nature to my project, it seemed to work. Can anyone explain why?

Was it helpful?

Solution 2

It seemed to work now, after I added the Gradle nature to my project, then cleaning and regenerating eclipse files.

OTHER TIPS

As far as I understand, --refresh-dependencies makes sure that the already cached dependencies are ignored and that dependencies are re-downloaded when they're needed.

Just use gradlew build, or gradlew test, and gradle will compile your tests, and thus download the missing dependencies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top