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.