Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New sourceSet by gradle cannot be seen in Eclipse

I have created additional source set called "integration-test" in my gradle project. Ewerything works fine, but eclipse cannot see dependency classes defined exactly for this source set.

enter image description here

subprojects {
        apply plugin: 'java'
        apply plugin: 'eclipse'

        repositories {
           mavenCentral()
        }

        sourceSets {
            integrationTest {
                java {
                    compileClasspath += main.output + test.output
                    runtimeClasspath += main.output + test.output
                    srcDir file('src/integration-test/java')
                }
                resources.srcDir file('src/integration-test/resources')
            }
        }

        configurations {
            integrationTestCompile.extendsFrom testCompile
            integrationTestRuntime.extendsFrom testRuntime
        }

        dependencies {
            testCompile 'junit:junit:4.12'
            testCompile 'org.mockito:mockito-all:1.10.19'
            integrationTestCompile 'org.springframework:spring-test:4.1.7.RELEASE'
            compile 'org.springframework:spring-context:4.1.7.RELEASE'
            compile 'org.springframework:spring-core:4.1.7.RELEASE'
        }

        task integrationTest(type: Test) {
            testClassesDir = sourceSets.integrationTest.output.classesDir
            classpath = sourceSets.integrationTest.runtimeClasspath
            outputs.upToDateWhen { false }
        }

        check.dependsOn integrationTest
        integrationTest.mustRunAfter test

        version = '1.0'
    }

When i build this project by command "build gradle", project is build, the only problem is with eclipse. If I change dependency 'org.springframework:spring-test:4.1.7.RELEASE' from "integrationTestCompile" to "testCompile", problem is gone.

like image 644
Cichy Avatar asked Aug 02 '15 19:08

Cichy


People also ask

How to run a Gradle project in Eclipse?

Create gradle project in eclipse and run the build. 1 1. Create java gradle project in eclipse. 2 2. Auto Generated files for Java gradle project in eclipse. 3 3. Run gradle build. 4 4. Run unit tests using gradle task. 5 5. Conclusion.

What are source sets in Gradle?

As the name implies, source sets represent a logical grouping of source files. We'll cover the configuration of Java projects, but the concepts are also applicable to other Gradle project types. 2.1. Default Project Layout

Where can I find the Gradle build framework tooling?

The Opens source project which creates this support itself is called Buildship and is led by Gradle Inc, the company behind the Gradle build framework. It is available on Buildship on Github. The tooling provides wizards for creating new Java based Gradle projects and options to execute Gradle build from the IDE.

Does Gradle-apt-plugin support annotation processing?

7. Annotation processing (apt) with Gradle in Eclipse 7.1. Overview The gradle-apt-plugin supports annotation processing for Gradle. It also supports using this in Eclipse and IntelliJ.


2 Answers

It is a little late to answer your question, but I just found a solution to this, since I had the exact same problem.

Adding this:

eclipse {
    classpath {
        plusConfigurations.add configurations.integrationTestCompile
        plusConfigurations.add configurations.integrationTestRuntime
    }
}

to the gradle file solved the problem. I hope it does the same for you.

like image 151
sbraconnier Avatar answered Sep 23 '22 07:09

sbraconnier


An approach that I found that worked really well for me is this test sets plugin: https://plugins.gradle.org/plugin/org.unbroken-dome.test-sets

It made it really easy to add integration tests to my module. And it works with the eclipse plugin automatically.

like image 39
Chris Avatar answered Sep 23 '22 07:09

Chris