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

if syntax error spotless talks about google format jdk version error #761

Closed
maxandersen opened this issue Dec 27, 2020 · 1 comment
Closed
Labels

Comments

@maxandersen
Copy link

I had a typo in one of my java files, like:
assertEquals(lines.stream().filter(x -> x.contains("jbang run ")).count(), ;'1);

notice the extra ;'.

when running spotless I get this error:

> java.lang.Exception: You are running Spotless on JRE 8, which limits you to google-java-format 1.7
  If you upgrade your build JVM to 11+, then you can use google-java-format 1.9, which may have fixed this problem.

spent quite some time figuring out why that was happening since I'm using eclipse() in my config - but in the end it was because of the syntax error so I assume there is some bad logic around when having to show the google-java-format exception.

gradle v6, id "com.diffplug.spotless" version "5.7.0", OSX:

spotless {
	lineEndings 'UNIX'
	format 'misc', {
		target '**/*.gradle', '**/*.md', '**/.gitignore'
		targetExclude 'CONTRIBUTORS.md', 'src/main/scripts/container/README.md', 'build/container/README.md' // all-contributor bot adds non-indented code
		trimTrailingWhitespace()
		indentWithTabs(4) // or spaces. Takes an integer argument if you don't like 4
		endWithNewline()
	}
	java {
		importOrder 'java', 'javax', 'org', 'com', 'dev.jbang', ''
		removeUnusedImports()
		eclipse().configFile "misc/eclipse_formatting_nowrap.xml"
	}
	format 'xml', {
		targetExclude 'build/test-results'
		target '**/*.xml', '**/*.nuspec'
	}
}

@nedtwigg
Copy link
Member

I've been following jbang, wish you success with that project! removeUnusedImports() is powered by google-java-format behind the scenes. We got lots of bug reports from folks using Java 9+ features but using Java 8 for their gradle build, in which case GJF throws "unable to parse" errors, which is what you ran into.

Spotless is optimized towards "we'll just fix it", rather than "error here, you have to fix it". See this comment for more details. Happy to take a PR which improves this situation, but our primary usecase is to standardize the style of working code.

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

2 participants