Spring boot missing HexCodec dependency

Hi All,

I am new with gradle and I started working on migrating my maven project to gradle, I have used the gradle init task to do the initial phase and create the elementary skeleton then I started adding manually the missing parts, my project is a Spring boot application and when I have tried running the app using gradle run, I encountered the following exception:

java.lang.NoClassDefFoundError: brave/internal/HexCodec

but in my build.gradle I have added the following dependency and it didn’t help:

implementation ‘io.opentracing.brave:brave-opentracing:0.33.7’

although it includes the missing file there, what I am missing here?

thanks in advance!

I usually have a bootRun task when creating Spring boot applications.

Your implementation line looks correct.

Please either attach the whole build.gradle file, or provide (at least) the plugins block.

Hi @christianGen , although running the bootRun task will give me the same error, here are the plugins I used:

   plugins {
    id 'java'
    id 'org.springframework.boot' version '2.4.2'
//    id 'com.ebay.build.assembler' version '0.1.0-RC6'
    id 'application'
    id 'pmd'
//    id 'checkstyle'

You don’t need the id 'application' plugin.

Do you use the spring-boot BOM?
(In kotlin: implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)))

If not you are missing the spring boot dependency plugin: id 'io.spring.dependency-management' version '1.0.11.RELEASE'

Easiest is probably to start with a build.gradle file from https://start.spring.io/

thanks for your answer, can you kindly explain for me the following:

  1. why there is no need foe the application plugin? won’t this run the application with defining the main class?

  2. why the spring-boot BOM is needed?

don’t have the same configuration as you listed above will try both, thanks!

The application plugin provides the run task.

Spring boot added their own run task: bootRun which adds (very little) additional functionality.

The BOM is used to control the versions of a spring boot’s dependencies and provide a central place to define and update those versions. Baeldung: Spring with Maven BOM

In a nutshell it specifies which versions of dependencies are acceptable for the spring boot version you are using.

Is the brave-opentracing jar included in the build/libs/xxx.jar file? (BOOT-INF/lib)?

got it, in my build directory can’t see the BOOT-INF/lib only my-app-name.jar and my-app-name-sources.jar under lib directory

The BOOT-INF/lib folder should be in the my-app-name.jar file (open it with a zip program).

@christianGen yes it is there with the correct version

and java -jar lib/my-app-name.jar gives you the java.lang.NoClassDefFoundError: brave/internal/HexCodec error?

no, the gradle run or gradle bootRun gives me this

just to confirm. java -jar lib/my-app-name.jar does work?

will try and update you

@christianGen the same error…

ok one thing I noticed building the project on another pc will work without errors…

do you use the same java version?

Maybe brave is now a module and doesn’t export the internal package.

yes, we use the same environment and the same development branch , also tried to remove the dependency above and the project was built successfully, I feel that this is something related to the IDE or the dependency indexes and not related to gradle but not sure

Actually whether the brave-opentracing jar is present is only marginally interesting.
The missing class is in the brave jar that is a transitive dependency of the former:

@Vampire when building the gradle project on another pc which has the same setup, the build succeeds only my local pc it always gets this exception of the missing missing file, tried to remove the dependency directory on my loacl m2 repository and build again but the dependency was not resolved or downloaded again which is so strange…

@Vampire @christianGen , ok when deleted the .m2/io directory didn’t see that the dependency was resolved and when inspected the maven POM found this:


the scope here is compile but in my gradle project the transitive dependency that brings it was defined as implementation would this affect the way it is handled by gradle?


I didn’t really understand what you say.
compile is the same as having nothing in the POM, as compile is the default scope.

As you are talking about your local maven repository, I assume you are using mavenLocal() and then my advise is, don’t do it. This is a broken-by-design directory that is a mixture of local repository and download cache. If you for example also use Maven on that box and resolve only the POM of a dependency, then only the POM is in maven local and when Gradle sees that, it sees a broken repository entry that in the best case throws an error, in worst case just behaves strangely. If you actually need to use maven local because you need a snapshot build of a non-Gradle project, then at least use mavenLocal as last entry in your list of repositories and use a repository content filter to only pull the exact defined dependency from that repository.