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
Add support for java 9 #7
Conversation
Super clever, thanks for the contribution @Sineaggi! Only one comment - any chance we can switch the GitHub Actions workflow to use matrix builds for the JDK version? Right now, we're only building for Java 1.8. Can we maybe make it build for 8, 9 and 17 (all of the stable ones)? That should allow us to exercise both paths of the change. The workflow file is here. Let me know if this makes sense! |
So off the top of my head we should be able to add support for 9 relatively easily, as 9 has been supported since gradle 4.3. Unfortunately for newer versions of java like 11 and 17, we'd either need to use java toolchains which were added in gradle 6.7 or upgrade all the way to gradle 7 (which removed the maven plugin in favor of the maven-publish plugin). |
Yeah, asking you to upgrade Gradle would be taking advantage of your good nature, I'm pretty sure 😉. So let's only add Java 9 for now. |
@skinny85 I've got a first pass of a partial upgrade to gradle 6.x, not sure if the test matrix is correct. The testing is a bit ugly since the import of |
Ugh just hit junit-team/junit4#1717, disabling 17 for now |
.github/workflows/build.yaml
Outdated
- name: Build and test the project | ||
env: | ||
JAVA_VERSION: ${{ matrix.version }} | ||
run: ./gradlew check javadoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we're introducing a new job here, instead of changing the existing one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None at all, will collapse them.
.github/workflows/build.yaml
Outdated
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 1.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this name needs to be updated.
.github/workflows/build.yaml
Outdated
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to use ${{ matrix.version }}
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but gradle plays catch-up with every new version of java. By using the matrix version of java with the toolchain we can use unsupported versions of gradle (like 17 for example) in gradle 6 for compilation/testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind either way, but it does mean testing on java 17 would require gradle 7.
Which shouldn't be too hard, considering we're now on gradle 6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with skipping Java 17 for now.
I'd be fine with changing to a |
That would make compiling under newer versions of java easier. We'd also be able to align main and test source sets, which would then make it easier to just use |
LMK what you'd prefer, I think the current way of using javaCompiler/javaLauncher ended up being pretty obtuse. |
I agree. Let's simplify by switching to |
@skinny85 I've switched to using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skinny85 I've switched to using
Class.forName
for all java versions. Simplified the build.gradle and the test matrix. The build process should be clearer now.
Thanks for the contribution - it looks fantastic now!
I just have a few last small finishing comments, if you'd be so kind 🙂.
@@ -5,17 +5,16 @@ on: [push, pull_request] | |||
jobs: | |||
build: | |||
runs-on: ubuntu-latest | |||
env: | |||
# disable the demon, as it's causing some problems | |||
GRADLE_OPTS: -Dorg.gradle.daemon=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to remove this?
Not sure how effective it is to use the daemon in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe in modern gradle the daemon spawns regardless, in ci it will shut down at the end of the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm 99% sure that system property disables the daemon, but it's not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was testing locally at least, these logs were printed.
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/6.9.2/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
I can add the flag back in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, it's not a big deal. Let's just leave it as-is. Thanks!
build.gradle
Outdated
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.6.2' | ||
testAnnotationProcessor(getProject()) | ||
testAnnotationProcessor('com.squareup:javapoet:1.8.0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this dependency for the third time? Would switching it from either compileOnly
or testCompileOnly
to compile
/ testCompile
above would allow us to remove this declaration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or can we at least remove the second instance of it, above (the testCompileOnly 'com.squareup:javapoet:1.8.0'
one)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testCompileOnly
is no longer necessary, but since the annotation processor hasn't been repackaged by the shadow plugin yet, we'll need to keep the testAnnotationProcessor
dependencies.
build.gradle
Outdated
dependencies { | ||
compileOnly 'com.squareup:javapoet:1.8.0' | ||
|
||
testCompileOnly 'com.squareup:javapoet:1.8.0' | ||
testCompile group: 'junit', name: 'junit', version: '4.11' | ||
testCompile group: 'junit', name: 'junit', version: '4.13.2' | ||
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.6.2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here:
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.6.2' | |
testCompile 'org.assertj:assertj-core:3.6.2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love these simplifications, thanks!
@@ -213,8 +212,20 @@ protected final String buildMethodName() { | |||
} | |||
|
|||
protected final AnnotationSpec generatedAnnotation() { | |||
Class<?> generatedAnnotation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of this variable name, mainly because it's the same as the method.
How about generatedAnnotationClass
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with separate helper method below.
Class<?> generatedAnnotation; | ||
try { | ||
// available since 9 | ||
generatedAnnotation = Class.forName("javax.annotation.processing.Generated"); | ||
} catch (ClassNotFoundException e) { | ||
try { | ||
generatedAnnotation = Class.forName("javax.annotation.Generated"); | ||
} catch (ClassNotFoundException ex) { | ||
// Shouldn't be possible. | ||
throw new IllegalStateException(ex); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind actually extracting this to a separate helper method? Something like private Class<?> determineGeneratedAnnotationClass() throws Exception { ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ClassNotFoundException ex) { | ||
// Shouldn't be possible. | ||
throw new IllegalStateException(ex); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this dead code, can you instead change this method to have throws Exception
(its caller already has it, so it shouldn't cause any problems), and remove this entire catch
statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
.github/workflows/build.yaml
Outdated
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 1.8 | ||
- name: Set up JDK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it legal to use dynamic expressions in step names? So this would become something like
- name: Set up JDK | |
- name: Set up JDK version ${{ matrix.version }} |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's find out!
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect, thanks @Sineaggi!
Could you release a version with Java 9+ support as a maven artifact on the central maven repository? Would be really nice to be able to use it as a normal dependency without maintaining an own copy of the binary. |
Yes! Apologies @der-R, I merged the PR, but completely blanked that I need to do a release! I'll do it this week (this is a new laptop where I don't have all of the stupid PGP stuff for Maven Central set up, so it will take a while), and I'll let you know when it's done! |
This adds support for the new
javax.annotation.processing.Generated
annotation under java 9. Under java 8 (and below) it will fall back to using the old annotation.Fixes #6