Gradle test succeeds but build fails with the same test failure!


(Gagan B Mishra) #1

I have a spring-boot application which is structured as gradle multi-project.

Gradle version : 3.3
Spring boot version : 1.5.4

The hierarchy looks like :

rootProject.name = 'omsProject'
include 'oms'
include 'customer-svc-client' 

As per the directory structure :

src/main/java
oms/src/main/java
oms/src/test/java
customer-svc-client/src/main/java
customer-svc-client/src/test/java

The subproject oms depends on customer-svc-client.

gradle test and gradle :oms:test both run just fine.

However, when I do gradle build, the :oms:test task fails with NoClassDefFoundError :

:oms:test

com.example.oms.service.OrderResourceTests > testGetAllOrdersCount FAILED
    java.lang.NoClassDefFoundError at OrderResourceTests.java:25
    Caused by: java.lang.ClassNotFoundException at OrderResourceTests.java:25

Stcktrace from the html test report shows :

java.lang.NoClassDefFoundError: com/example/grasclient/CustomerServiceClient
....
....
Caused by: java.lang.ClassNotFoundException: com.example.grasclient.CustomerServiceClient

I tried adding testCompile, and adding test classpath but that didnt help.

Can anyone help me in this ?


(Jarosław Czekalski) #2

I have a similar issue at work. How did you resolve it? I guess we need to prepare a simple project demonstrating the issue and file it as a bug.

In my case I had the following dependencies:
B needs A
A-test needs B

So gradle should process it in the following order:
A, B, A-test

Somehow it is possible in “test”, but fails with “build”.

My workaround was removing this strange dependency “A-test needs B”.