0

I have a gradle project in Java17 and when running a test I'm getting the following error:

java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement

This is how the test look like:

public class SettingsServiceTest extends AbstractIntegrationTest {
@Autowired
private SettingsService settingsService;


@Test
void shouldReturnMandatorySetting() {
    wireMockGetConfig();
 
    String res = settingsService.getMandatorySetting();
    Assertions.assertEquals(res, "setting");
}

The wiremockGetConfig method:

 protected void wireMockGetConfig() {
    givenThat(get(urlPathEqualTo("/settings/appid"))
            .willReturn(aResponse()
                    .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
                    .withBody(readResource(SETTINGS_JSON_FILE))
                    .withStatus((Response.SC_OK))));
}

As you can see I'm trying to mock the response of a client. The response is going to be a json file. I've used this pattern multiple times and it always worked perfectly. Recently we migrated our apps to Java17 and after looking at this older thread I'm starting to think I need to configure something. I've no references to javax in the code (we already migrated for Java17).

I've already tried to add the dependencies mentioned in the accepted answer of the above thread:

implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"

with no changes/success. I've also tried using version 4.0.0 with no difference.

Akinn
  • 1,896
  • 4
  • 23
  • 36
  • Just as sanity check did you try to use `api` instead of `implementation` be be sure it is this module which misses the dependency and not some sub module which would not be covered by `implementation`. – Markus Schreiber Jun 19 '23 at 12:40
  • I've tried. Same failure. – Akinn Jun 19 '23 at 12:50
  • 1
    jakarta.xml.bind is the successor library auf jaxb but it is not directly compatible as the package name has changed. So each library and you code has to be migrated to this new library. `javax.xml.bind`-> `jakarta.xml.bind`. – Robert Jun 25 '23 at 11:03

1 Answers1

0

There was another dependency which was pulling up javax modules. Refactoring dependencies solved the issue

Akinn
  • 1,896
  • 4
  • 23
  • 36