Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

Error when trying to apply 'java-test-fixtures' plugin using gradle

I have a java project that uses fixtures where both unit and integration test use fixtures. Right now fixture classes are duplicated in every single module and we would like to have a single one where both IT and UT can access there.

Gradle recommends java-test-fixtures plugin but when we apply it we see the following error and doesn't work:

Warning:root project 'backend': Unable to resolve additional project configuration. Details: java.lang.IllegalStateException: Resolving dependency configuration 'testFixturesCompileOnly' is not allowed as it is defined as 'canBeResolved=false'. Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'testFixturesCompileOnly' should be resolved.

Here is the build.gradle file

plugins {
    id 'org.springframework.boot' version '2.4.1'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'idea'
    id 'java-test-fixtures'
}

group = 'com.dumbbell'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.flywaydb:flyway-core'
    compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'com.h2database:h2'
    runtimeOnly 'org.postgresql:postgresql'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.security:spring-security-test'
    testImplementation 'org.mockito:mockito-core:2.7.22'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

test {
    useJUnitPlatform()
}

// Integration test module
sourceSets {
    integrationTest {
        compileClasspath += sourceSets.main.output
        runtimeClasspath += sourceSets.main.output
    }
}

configurations {
    integrationTestImplementation.extendsFrom testImplementation
    integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
}

task integrationTest(type: Test) {
    useJUnitPlatform()
    description = 'Runs integration tests.'
    group = 'verification'

    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
}

idea {
    module {
        testSourceDirs += project.sourceSets.integrationTest.java.srcDirs
    }
}

// End 2 end test module
sourceSets {
    end2end {
        compileClasspath += sourceSets.main.output
        runtimeClasspath += sourceSets.main.output
    }
}

configurations {
    end2endImplementation.extendsFrom testImplementation
    end2endRuntimeOnly.extendsFrom testRuntimeOnly
}

task end2end(type: Test) {
    useJUnitPlatform()
    description = 'Runs integration tests.'
    group = 'verification'

    testClassesDirs = sourceSets.end2end.output.classesDirs
    classpath = sourceSets.end2end.runtimeClasspath
}

idea {
    module {
        testSourceDirs += project.sourceSets.end2end.java.srcDirs
    }
}

Any clue on how to fix it?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...