dimanche 19 avril 2020

How to reference to a test-project in a multi-project setup with gradle?

I've got a multi-project gradle setup.

:client:core
:client:desktop
:tests

In my ":tests" project, I've got a file structure like that

src/test/java/my/domain/as/package/TestRunner.java

In my ":client:desktop" project, I've got a file structure like that

src/main/...
src/test/java/my/domain/as/package/ExampleTest01.java

My gradle files looks like that: (desktop-client)

project(":client:desktop") {
    apply plugin: "java"

    java {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    sourceSets.main.java.srcDirs = [ "src/main/java/" ]
    sourceSets.test.java.srcDirs = [ "src/test/java/" ]

    dependencies {
        testCompile project(":tests")
        api project(":client:core")
        ...
    }
}

(tests-project)

project(":tests") {
    apply plugin: "java-library"
    apply plugin: "java"

    java {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    sourceSets.test.java.srcDirs = ["src/test/java/"]

    dependencies {

        compile project(":client:core")

        compile "junit:junit:4.+"
        compile "org.mockito:mockito-all:1.9.+"

        ...

        testCompile 'junit:junit:4.+'
        testCompile "org.mockito:mockito-all:1.9.+"

        ...
    }
}

Now in my ExampleTest01.java I've got the following content:

package my.domain.as.package.client.desktop;

import ...
import org.junit.Test;
import org.junit.runner.RunWith;
import my.domain.as.package.tests.MyTestRunner;

import static org.junit.Assert.assertTrue;

@RunWith(MyTestRunner.class)
public class ExampleTest01 {

    @Test
    public void simpleTest() {

        assertTrue(true);
    }
}

In my <:tests>/src/test/java/my/domain/as/package/MyTestRunner.java I've got something like that:

package my.domain.as.package;


public class MyTestRunner extends BlockJUnit4ClassRunner {
    ...
}

My Problem is, that the linking tot the test project won't work so the import within the concrete ExampleTest01.java could not get resolved.

It seems like gradle can't resolve or bind these both projects but I don't know why. Can you help me with that?

Aucun commentaire:

Enregistrer un commentaire