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

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 : = 'omsProject'
include 'oms'
include 'customer-svc-client' 

As per the directory structure :


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 :


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

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 ?

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”.