Skip to content

Maven shading of Jackson should exclude Module ServiceLoader files #2620

@drekbour

Description

@drekbour

👓 What did you see?

When using new ObjectMapper().findAndRegisterModules(), Jackson's ServiceLoader mechanism discovers the following file embedded in cucumber-core.

jar:file:/I:/ds/.m2_repo/io/cucumber/cucumber-core/7.8.0/cucumber-core-7.8.0.jar!/META-INF/services/com.fasterxml.jackson.databind.Module

This references a class that is not packaged (ok, so it's shaded but let's pretend we didn't see that) so fails if the user doesn't have it on the classpath.

java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.datatype.jdk8.Jdk8Module not found
	at java.util.ServiceLoader.fail(ServiceLoader.java:239)
	at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1105)
	at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1089)
	at com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules(ObjectMapper.java:1139)

✅ What did you expect to see?

BAU

📦 Which tool/library version are you using?

cucumber-jvm 7.8.0

🔬 How could we reproduce it?

Import vanilla Jackson without any optional stuff.

      <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
      </dependency>

and include this in the Java: new ObjectMapper().findAndRegisterModules()

📚 Any additional context?

Use of maven-shade-plugin should exclude that file

<artifact>com.fasterxml.jackson.datatype:jackson-datatype-jdk8</artifact>
<excludes>
<exclude>**/module-info.class</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/LICENSE</exclude>
</excludes>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions