The java-test-fixtures plugin not working with dgs framework

386 Views Asked by At

I tried to use java-test-fixtures plugin in project with dgs framework but it looks it is not working. It was working with version 5.5.3 (spring boot 2.7) of dgs framework but since 6 (spring boot 3) no.

I have simple spring boot project with dgs framework. I try to run an empty test but it threw exception with message:

 Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgsQueryExecutor' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dgsQueryExecutor' parameter 1: Error creating bean with name 'schema' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'schema' threw exception with message: errors=['SomeEntity' type [@1:1] tried to redefine existing 'SomeEntity' type [@1:1]]

My simple project: https://github.com/tomsvet/dgs_demo

My build.gradle.kts file looks:

 plugins {
    id("org.springframework.boot") version "3.1.0" apply false
    id("io.spring.dependency-management") version "1.1.0"
    id("com.netflix.dgs.codegen") version "5.11.1" apply false
    kotlin("jvm") version "1.8.21"
    kotlin("plugin.spring") version "1.8.21"
    id("java-test-fixtures")
 }
 
 group = "com.dgs.demo"
 version = "0.0.1-SNAPSHOT"
 java.sourceCompatibility = JavaVersion.VERSION_17
 
 repositories {
    mavenCentral()
 }
 dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release"))
    implementation("com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
 }

I investigate that this error is return only when I used id("java-test-fixtures"). Could anyone help what to do when I want to use test fixtures plugin with netflix dgs?

Solution:

What I found - When using the Java test fixtures plugin, Gradle 6 changed the way it adds the production source code (main source set) to the classpath when compiling or running tests. It now uses the jar file instead of the compilation output directory (build/classes/java/main). Solution is to remove jar files from the classpath:

tasks.withType<Test>{ 
val ignoredJarNames = files(tasks.jar).map { it.name }
    classpath = classpath.filter { cpItem -> !ignoredJarNames.contains(cpItem.name) 
} 

or

 tasks.withType<Test>{classpath -= files(tasks.jar)}

More info: https://github.com/gradle/gradle/issues/11696

0

There are 0 best solutions below