Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading of FormatterProperties from resource #2428

Open
philipp94831 opened this issue Feb 21, 2025 · 2 comments
Open

Allow loading of FormatterProperties from resource #2428

philipp94831 opened this issue Feb 21, 2025 · 2 comments
Labels

Comments

@philipp94831
Copy link

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

@nedtwigg
Copy link
Member

For Gradle, I recommend https://github.com/diffplug/blowdryer. I don't know enough about Maven to make any recommendations here.

@rnc
Copy link

rnc commented Feb 26, 2025

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, #2361 might solve your use-case ? (then the resources could be loaded from a resource using a TextResource).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants