Add Dependencies to Eclipse with Gradle

I use the Gradle IDE plugin for Eclipse and I created a custom task in the build.gradle file:

sourceSets {
    unitTest {
        java.srcDirs = ['tests']
    }
}

dependencies {
    unitTestCompile files("$project.buildDir/classes/debug")
    unitTestCompile 'junit:junit:4.11'
    unitTestCompile 'org.robolectric:robolectric:2.1.1'
    unitTestCompile 'com.google.android:android:4.0.1.2' 
}

configurations {
    unitTestCompile.extendsFrom runtime
    unitTestRuntime.extendsFrom unitTestCompile
}

task unitTest(type:Test, dependsOn: assemble) {
    description = "run unit tests"
    testClassesDir = project.sourceSets.unitTest.output.classesDir
    classpath = project.sourceSets.unitTest.runtimeClasspath
}

build.dependsOn unitTest

The problem is that the links I referenced are not added in Eclipse and I get the error that import org.junit.Test;, import org.robolectric.Robolectric;etc. cannot be allowed. I tried right-clicking on the project -> Gradle -> Update Dependencies, but to no avail.

+4
source share
1 answer

Found a solution on my own. Add this to the build.gradle file:

apply plugin: 'eclipse'
eclipse {
    classpath {    
        plusConfigurations += configurations.unitTestCompile
      }
}

and then right click on the project -> Gradle -> Update Dependencies.

+3
source

Source: https://habr.com/ru/post/1524266/


All Articles