Skip to content

Commit

Permalink
Build test code using JDK 17
Browse files Browse the repository at this point in the history
This enables usage of text blocks, which in combination with IntelliJ
IDEA's _language injection_ functionality greatly simplify writing
`BugChecker` tests.
  • Loading branch information
Stephan202 committed Aug 14, 2022
1 parent 773226a commit ff436ec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
17 changes: 6 additions & 11 deletions error-prone-contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ Two other goals that one may find relevant:
`target/pit-reports/index.html` files. For more information check the [PIT
Maven plugin][pitest-maven].

When running the project's tests in IntelliJ IDEA, you might see the following
error:
```
java: exporting a package from system module jdk.compiler is not allowed with --release
```

If this happens, go to _Settings -> Build, Execution, Deployment -> Compiler ->
Java Compiler_ and deselect the option _Use '--release' option for
cross-compilation (Java 9 and later)_. See [IDEA-288052][idea-288052] for
details.
The `BugChecker` implementations provided by this project are tested using
Error Prone's `CompilationTestHelper` and `BugCheckerRefactoringTestHelper`
classes. These utilities accept text blocks containing inline Java source code.
To ease modification of this inline source code, consider using IntelliJ IDEA's
[language injection][idea-language-injection] feature.

### Contribution guidelines

Expand Down Expand Up @@ -342,7 +337,7 @@ Refaster's expressiveness:
[forbidden-apis]: https://github.com/policeman-tools/forbidden-apis
[fossa]: https://fossa.io
[google-java-format]: https://github.com/google/google-java-format
[idea-288052]: https://youtrack.jetbrains.com/issue/IDEA-288052
[idea-language-injection]: https://www.jetbrains.com/help/idea/using-language-injections.html
[maven]: https://maven.apache.org
[modernizer-maven-plugin]: https://github.com/gaul/modernizer-maven-plugin
[pitest]: https://pitest.org
Expand Down
32 changes: 31 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<version.findbugs-format-string>3.0.0</version.findbugs-format-string>
<version.guava-beta-checker>1.0</version.guava-beta-checker>
<version.jdk>11</version.jdk>
<version.jdk.test>17</version.jdk.test>
<version.maven>3.6.3</version.maven>
<version.mockito>4.6.1</version.mockito>
<version.nopen-checker>1.0.1</version.nopen-checker>
Expand Down Expand Up @@ -854,6 +855,8 @@
<parameters>true</parameters>
<source>${version.jdk}</source>
<target>${version.jdk}</target>
<testSource>${version.jdk.test}</testSource>
<testTarget>${version.jdk.test}</testTarget>
<!-- Erroneously inverted logic... for details, see
https://issues.apache.org/jira/browse/MCOMPILER-209. -->
<useIncrementalCompilation>false</useIncrementalCompilation>
Expand Down Expand Up @@ -897,7 +900,7 @@
<includes>src/main/resources/**/*.properties,src/test/resources/**/*.properties</includes>
</requireEncoding>
<requireJavaVersion>
<version>${version.jdk}</version>
<version>${version.jdk.test}</version>
</requireJavaVersion>
<requireMavenVersion>
<version>${version.maven}</version>
Expand Down Expand Up @@ -1740,5 +1743,32 @@
</plugins>
</build>
</profile>
<profile>
<!-- This profile is active when the project is loaded into
IntelliJ IDEA. Drop it once IDEA properly supports the `testSource`
and `testTarget` settings of the `maven-compiler-plugin`, such that
specifying different language levels for main and test code works
out of the box. See
https://youtrack.jetbrains.com/issue/IDEA-85478. -->
<id>idea</id>
<activation>
<property>
<name>idea.maven.embedder.version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${version.jdk.test}</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>

0 comments on commit ff436ec

Please sign in to comment.