phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
115 stars 36 forks source link

Reduce jar size when shading ph-schematron-pure #163

Closed fhnaumann closed 8 months ago

fhnaumann commented 8 months ago

I'm depending on ph-schematron-pure for validating incoming JSON/XML data against my own schematron file. Everything works fine but unfortunately this library causes my shaded jar to be really big. Especially Saxon-HE (~5mb), ph-commons (~1.3mb) and xmlresolver (~1mb) increase the total jar size a lot. Without ph-schematron-pure my jar is roughly 2mb large, with this dependency it goes up to nearly 12mb. Maybe if it helps, I'm only using this functionality:

var schematronResourcePure = SchematronResourcePure.fromFile(schematronFile);
Source streamSource = new StreamSource(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
SchematronOutputType schematronOutputType = schematronResourcePure.applySchematronValidationToSVRL(streamSource);
ICommonsList<AbstractSVRLMessage> svrlFailedAsserts = SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(schematronOutputType);
// and then iterate the list and convert each object into my own model

Is there a way to reduce the size? If not, then my only options seems to split the project into 2 modules, one for validation and one for my application.

phax commented 8 months ago

@fhnaumann Thanks for reaching out to me. I agree, that 12 MB is very large, and potentially too large. The problem is the usage of XPath 2 - as soon as you need more then XPath 1, Saxon is unavoidable to my understanding. So if you can make sure, that you only use XPath 1 in your expressions, you can try to simple exclude the Saxon dependency which will also remove the xmlresolver

hth, Philip