GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support google-java-format 1.8+ by benkard · Pull Request #563 · diffplug/spotless

Conversation

@benkard

@benkard benkard commented May 2, 2020

Copy link
Copy Markdown
Contributor

In google-java-format 1.8, the signature of
RemoveUnusedImports#removeUnusedImports changed and the
RemoveUnusedImports$JavadocOnlyImports class was removed entirely.
With this patch, GoogleJavaFormatStep detects which version of the
method is available and calls the right one.

Fixes #562.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@benkard
Support google-java-format 1.8+.
dbc4762
In google-java-format 1.8, the signature of
RemoveUnusedImports#removeUnusedImports changed and the
RemoveUnusedImports$JavadocOnlyImports class was removed entirely.
With this patch, GoogleJavaFormatStep detects which version of the
method is available and calls the right one.

Fixes diffplug#562.
@benkard benkard mentioned this pull request May 2, 2020
ClassNotFoundException with google-java-format 1.8 #562
Closed
@benkard
Add change log entries for PR diffplug#563.
6f7aa17
@nedtwigg nedtwigg mentioned this pull request May 2, 2020
Todo list if/when we drop compat for an older Gradle version #504
Closed
3 tasks done
nedtwigg added 9 commits May 2, 2020 21:48
@nedtwigg
Add ability to detect what version of JRE we're running on, and use i…
2d4eeda
…t to get the build to work on both JRE 8 and 11.
@nedtwigg
Fix extra tests in Travis.
8bfc8b3
@nedtwigg
Modifications to get ErrorShouldRethrow to pass on Gradle 5 (oldest…
6d47868
… gradle version that supports Java 11).
@nedtwigg
Fixup - all tests should now pass on Java 8 and 11.
9ce3dff
@nedtwigg
Disable spotbugs on Java 11.
717b479
@nedtwigg
Add test for google-java-format 1.8+, which is skipped on JRE 8.
c0a8469
@nedtwigg
Disable javadoc on 11.
5af53aa
@nedtwigg
Disable the maven build for Java 11.
88ca46e
@nedtwigg
Fix the small behavior change in the latest google-java-format.
11f58d8
@nedtwigg

nedtwigg commented May 3, 2020

Copy link
Copy Markdown
Member

@diffplug/spotless Just FYI, this is the first PR we have received where the formatter requires Java 11+, and there are more coming (#547). As a result, we now need our tests to run on Java 11.

This PR represents the minimal effort needed to merge support for google-java-format 1.8 with tests. We now run the whole build on both 8 and 11. The only things I disabled on 11 are things which are broken there, namely

  • plugin-maven
  • javadoc generation
  • spotbugs (I think already fixed in newer spotbugs)

The trickier part is that now there are some tests which you can't run on 8, because they'll break. Also, Gradle 5.0 is the oldest that can run on Java 11, so you can't run old-gradle-tests on 11.

I'm very open to PRs for a more comprehensive solution, but I think it's fine to play whack-a-mole until a pattern merges. Here's the gist of the 8 / 11 test infrastructure I put in:

spotless/testlib/src/main/java/com/diffplug/spotless/JreVersion.java

Lines 20 to 23 in 11f58d8

public enum JreVersion {
_8, _11;
public static JreVersion thisVm() {

spotless/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java

Lines 30 to 35 in 11f58d8

@Test
public void behavior18() throws Exception {
if (JreVersion.thisVm() == JreVersion._8) {
// google-java-format requires JRE 11+
return;
}

spotless/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationTest.java

Lines 60 to 78 in 11f58d8

/**
* For Java 11+, Gradle 5 is the minimum.
* So if you ask for less than Gradle 5, you get it on Java 8, but on Java 11 you get promoted to Gradle 5.
* If you ask for more than Gradle 5, you'll definitely get it.
*/
protected static String requestGradleForJre8and11(String ver) {
JreVersion jre = JreVersion.thisVm();
// @formatter:off
switch (jre) {
case _8: return ver;
case _11: return Double.parseDouble(ver) < 5.0 ? "5.0" : ver;
default: throw new IllegalStateException("Spotless build is only supported on Java 8 and Java 11");
}
// @formatter:on
}
protected final GradleRunner gradleRunner() throws IOException {
return GradleRunner.create()
.withGradleVersion(requestGradleForJre8and11("2.14"))

jbduncan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nedtwigg added 2 commits May 3, 2020 00:03
@nedtwigg
Add Java 11 info to the changelogs.
7ebb481
@nedtwigg
Use the same mechanism to disable tasks on Java 11 throughout the build.
0104f6d
@nedtwigg
nedtwigg merged commit de2d9b6 into diffplug:master May 3, 2020
@distributedlock distributedlock mentioned this pull request May 4, 2020
feat(ktfmt): add ktfmt a new Kotlin formatter from Facebook Incubator #569
Merged
@nedtwigg

nedtwigg commented May 5, 2020

Copy link
Copy Markdown
Member

Released in plugin-gradle 3.29.0, and plugin-maven 1.31.0

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ClassNotFoundException with google-java-format 1.8

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@benkard @nedtwigg
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.