gradle не может найти сгенерированный Lombok конструктор в интеграционном тесте - PullRequest
1 голос
/ 30 марта 2019

У меня есть интеграционный тест, в котором есть внутренний класс с аннотациями lombok.Похоже, это

@Test(dataProvider = "jsonDiff")
public class JaversDiffIntegrationTest {

    public void shouldCompareEntities(Person input1, Person input2, String expectedJson)
        throws JSONException {
        Person p1 = new Person("p_id", "Jack");
        Person p2 = new Person("p_id", "Michael");
        ....
    }

    @TypeName("TestEntityPerson")
    @Data
    @AllArgsConstructor
    private class Person {
        private String id;
        private String name;
    }

В Idea я включил обработку аннотаций и, по крайней мере, он способен компилироваться.Когда я пытаюсь запустить clean build через gradlew, я получаю ошибку

constructor Person in class JaversDiffIntegrationTest.Person cannot be applied to given types;
    Person p2 = new Person("p_id", "Michael");
                    ^
    required: no arguments
    found: String,String

Кажется, он не видит lombok сгенерированных конструкторов.Мой build.gradle выглядит так (я использую gradle5)

apply plugin: 'idea'

// TODO: move to integration-test.gradle
sourceSets {
    integrationTest {
        java.srcDir 'src/testInteg/java'
        resources.srcDir 'src/testInteg/resources'
    }
}

configurations {
    integrationTestImplementation.extendsFrom implementation
    integrationTestRuntimeOnly.extendsFrom runtimeOnly
}

task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath + sourceSets.test.runtimeClasspath
    outputs.upToDateWhen { false }
    mustRunAfter test

    useTestNG() {
        suites 'src/testInteg/resources/testng.xml'
    }

    testLogging {
        showStandardStreams = true
    }
}

check.dependsOn integrationTest

dependencies {
    implementation "javax.validation:validation-api:1.1.0.Final"
    testImplementation "junit:junit:4.11"

    testImplementation "org.spockframework:spock-core:1.3-groovy-2.5"
    testImplementation "org.codehaus.groovy:groovy-all:2.5.6"

    implementation "org.javers:javers-core:5.3.2"
    annotationProcessor "org.projectlombok:lombok:1.18.6"
    implementation "org.projectlombok:lombok:1.18.6"

    integrationTestImplementation "org.testng:testng:6.14.3"
    integrationTestImplementation "org.skyscreamer:jsonassert:1.5.0"
    integrationTestImplementation "com.google.code.gson:gson:2.8.5"
    integrationTestImplementation "commons-io:commons-io:2.6"
}

В чем проблема?Может быть, у меня есть проблемы с конфигурацией integrationTest?

1 Ответ

2 голосов
/ 31 марта 2019

Я считаю, что критически важный бит, который вам не хватает, - это конфигурация процессора аннотаций для вашего integrationTest набора источников:

    integrationTestAnnotationProcessor "org.projectlombok:lombok:1.18.6"

В следующем вы можете найтиавтономный рабочий пример (протестирован с Gradle 5.3.1).Это не совсем ваш проект, но он должен быть достаточно близко, чтобы вы могли на правильном пути:

build.gradle

apply plugin: 'java'

sourceSets {
    integrationTest {
        java.srcDir 'src/testInteg/java'
        resources.srcDir 'src/testInteg/resources'
    }
}

configurations {
    integrationTestImplementation.extendsFrom testImplementation
    integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
}

task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath + sourceSets.test.runtimeClasspath
}

repositories {
    jcenter();
}

dependencies {
    implementation "org.projectlombok:lombok:1.18.6"

    testImplementation "junit:junit:4.11"

    integrationTestAnnotationProcessor "org.projectlombok:lombok:1.18.6"
}

src/testInteg/java/MyTest.java

public class MyTest {

  @org.junit.Test
  public void test() {
    new Person("foo", "bar");
    assert true;
  }

  @lombok.AllArgsConstructor
  private class Person {
    private String id;
    private String name;
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...