gantsign/ktlint-maven-plugin

Configuring version of ktlint

binkley opened this issue · 2 comments

A lovely plugin, thank you! This is so much nicer to work with than creating an ant runner.

A feature request: I'd like to specify the version of ktlint used. Perhaps I can do that, but I did not see how from the Usage documentation or the Check goal.

You can specify the ktlint version in the standard Maven way by overriding the plugin dependencies. One note of caution, ktlint releases often have breaking API changes that require plugin changes, so overriding the ktlint version the plugin uses may cause it to fail. That's the main reason I haven't documented this in the main project documentation, but if you want to have a go the following should work:

<build>
  <plugins>
    ...
    <plugin>
      <groupId>com.github.gantsign.maven</groupId>
      <artifactId>ktlint-maven-plugin</artifactId>
      <version>${ktlint-maven-plugin.version}</version>
      <executions>
        <execution>
          <id>format-and-check</id>
          <goals>
            <goal>format</goal>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
      <dependencies>
        <dependency>
          <groupId>com.pinterest.ktlint</groupId>
          <artifactId>ktlint-core</artifactId>
          <version>${ktlint.version}</version>
        </dependency>
        <dependency>
          <groupId>com.pinterest.ktlint</groupId>
          <artifactId>ktlint-reporter-checkstyle</artifactId>
          <version>${ktlint.version}</version>
        </dependency>
        <dependency>
          <groupId>com.pinterest.ktlint</groupId>
          <artifactId>ktlint-reporter-json</artifactId>
          <version>${ktlint.version}</version>
        </dependency>
        <dependency>
          <groupId>com.pinterest.ktlint</groupId>
          <artifactId>ktlint-reporter-plain</artifactId>
          <version>${ktlint.version}</version>
        </dependency>
        <dependency>
          <groupId>com.pinterest.ktlint</groupId>
          <artifactId>ktlint-ruleset-experimental</artifactId>
          <version>${ktlint.version}</version>
        </dependency>
        <dependency>
          <groupId>com.pinterest.ktlint</groupId>
          <artifactId>ktlint-ruleset-standard</artifactId>
          <version>${ktlint.version}</version>
        </dependency>
      </dependencies>
    </plugin>
    ...
  </plugins>
</build>

@freemanjp Ah, I see the problem you explain. I'm glad you're dealing with a fast-changing API, and not me! Thank you again for the plugin.