Allow loading of FormatterProperties from resource
Currently it is only possible to load FormatterProperties from a File (e.g., XML in the case of eclipse) or String-based properties (https://github.com/diffplug/spotless/blob/4dd0095437906713fc6bad3a2e160646e11b419a/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java).
However, we would like to ship our XML codestyle definition as a resource file. This cannot be loaded by spotless unless we create a temporary file. Alternatively we would need to manually convert the XML to String-based properties and basically copy the behavior of XMLParser.
Therefore, it would be greate to be able to load FormatterProperties from an input stream (by specifying the file type) or even directly from a resource identifier
For Gradle, I recommend https://github.com/diffplug/blowdryer. I don't know enough about Maven to make any recommendations here.
Maven is straightforward (although it would have been useful to have this in the documentation) :
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.jboss.pnc</groupId>
<artifactId>ide-config</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<configuration>
<java>
<removeUnusedImports/>
<importOrder>
<file>java-import-order.txt</file>
</importOrder>
<eclipse>
<file>java-formatter.xml</file>
</eclipse>
<lineEndings>UNIX</lineEndings>
</java>
</configuration>
For Gradle, while #2343 helped a lot, https://github.com/diffplug/spotless/pull/2361 might solve your use-case ? (then the resources could be loaded from a resource using a TextResource).
With the advent of #2361 and the release of 7.2.1 its possible for Gradle (kotlin) to do something like:
val spotlessConfig by configurations.creating
dependencies {
spotlessConfig("org.jboss.pnc:ide-config:1.1.0")
}
spotless {
java {
removeUnusedImports()
importOrder(resources.text.fromArchiveEntry(spotlessConfig, "java-import-order.txt").asString())
eclipse().configXml(resources.text.fromArchiveEntry(spotlessConfig, "java-formatter.xml").asString())
}
}
@nedtwigg Would it be helpful to add something like these examples to the documentation?
docs such as that would be very helpful! Looks like this issue has been resolved.
@nedtwigg I think I may have confused the situation ; I meant to submit new documentation :-) ; as a potential PR I've submitted #2643 to give an example in both the maven and gradle plugin READMEs.