Repository navigation
Description
What happens
After #261 the Gradle plugin has no Groovy sources, but XmlUtils and ConfigureJavaFormatterXml still read and write .idea/open-java-format.xml, .idea/workspace.xml and .idea/externalDependencies.xml with Groovy's XmlParser, XmlNodePrinter and groovy.util.Node. The plugin does not declare Groovy: the classes come with gradleApi() at compile time and, at run time, from the Groovy that the user's Gradle bundles, so what is there is up to Gradle. That broke once: Groovy 4, in Gradle 9, dropped groovy.util.XmlParser, and the plugin failed with NoClassDefFoundError: groovy/util/XmlParser (palantir#1536).
Proposal
Parse with javax.xml.parsers.DocumentBuilder and edit the DOM, and drop the groovy.* imports from XmlUtils, ConfigureJavaFormatterXml and ConfigureJavaFormatterXmlTest. Write the files in UTF-8, which IntelliJ uses, instead of Charset.defaultCharset().
Why on its own
The text of the files changes. They are the developer's own files, which IntelliJ rewrites too, and ConfigureJavaFormatterXmlTest compares their text exactly. Tried on an externalDependencies.xml that lists one plugin, adding a second (JDK 21, Groovy 4.0.33 from Gradle 9.9.1):
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalDependencies">
<plugin min-version="5.0" id="CheckStyle-IDEA" />
</component>
</project>XmlNodePrinter with setPreserveWhitespace(true), as XmlUtils writes today:
<project version="4">
<component name="ExternalDependencies">
<plugin min-version="5.0" id="CheckStyle-IDEA"/>
<plugin id="open-java-format"/>
</component>
</project>The JDK's Transformer with INDENT and an indent amount of 2 (the blank-looking lines hold spaces):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project version="4">
<component name="ExternalDependencies">
<plugin id="CheckStyle-IDEA" min-version="5.0"/>
<plugin id="open-java-format"/>
</component>
</project>- Today the plugin already drops IntelliJ's XML declaration and the space IntelliJ writes before
/>. TheTransformerwrites a declaration of its own, withstandalone="no". - The
Transformerindents on top of the whitespace text the parser kept. Either strip whitespace-only text before writing, or print the tree with a small printer of our own. - The DOM writes attributes in alphabetical order (
idbeforemin-version);XmlNodePrinterkeeps the order of the file.
The aim worth a test: a file the plugin has nothing to change in comes out byte for byte the same, which is not the case today.
Activity