How to fix Xerces Error?

Error: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration.
I’m using the Xerces jar in a gradle project, I use then the jar of this project inside a gradle plugin: In fact, I’m developing a gradle plugin with custom tasks that use some functions of the gradle project jar; when I try to run the tasks, I have this error; however when I try to run the function from the gradle project it works correctly. When I tried to search on the net, I found that the cause of the error is that the JRE packages a version of Xerces but I don’t know how to resolve the problem…