'Jackson version conflict in groovy

When I run the code below using groovy 3.0.2 I get an error because groovy/lib dir already has some older version of jackson and for some reason some of them get used instead of version I specify in Grapes config. How can I force groovy to not use jackson from groovy/lib?

@Grapes([
    @Grab(group = 'com.fasterxml.jackson.core', module = 'jackson-annotations', version = '2.12.4', force = true),
    @Grab(group = 'com.fasterxml.jackson.core', module = 'jackson-core', version = '2.12.4', force = true),
    @Grab(group = 'com.fasterxml.jackson.core', module = 'jackson-databind', version = '2.12.4', force = true),
    @Grab(group = 'com.fasterxml.jackson.datatype', module = 'jackson-datatype-jsr310', version = '2.12.4', force = true),
    @Grab(group = 'com.fasterxml.jackson.dataformat', module = 'jackson-dataformat-xml', version = '2.12.4', force = true)
])

new com.fasterxml.jackson.dataformat.xml.XmlMapper()

The error:

java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()Lcom/fasterxml/jackson/databind/cfg/MutableCoercionConfig;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source