镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Allow loading of FormatterProperties from resource #2428

Closed

Description

@philipp94831

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

Activity

  1. nedtwigg commented on Feb 23, 2025

    @nedtwigg
    Member

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

  2. rnc commented on Feb 26, 2025

    @rnc
    Contributor

    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).

  3. rnc commented on Aug 6, 2025

    @rnc
    Contributor

    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?

  4. nedtwigg commented on Sep 24, 2025

    @nedtwigg
    Member

    docs such as that would be very helpful! Looks like this issue has been resolved.

  5. rnc commented on Sep 25, 2025

    @rnc
    Contributor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions