https://github.com/eitansuez/boot-maven-target
Simple example illustrating controlling the java compatibility level in a maven project.
https://github.com/eitansuez/boot-maven-target
Last synced: over 1 year ago
JSON representation
Simple example illustrating controlling the java compatibility level in a maven project.
- Host: GitHub
- URL: https://github.com/eitansuez/boot-maven-target
- Owner: eitansuez
- Created: 2019-01-01T00:15:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-01T00:15:13.000Z (over 7 years ago)
- Last Synced: 2025-01-08T14:43:26.339Z (over 1 year ago)
- Language: Java
- Size: 46.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Example boot project illustrating use of sourceCompatibility.
## Assumptions
* You have openjdk-11 installed on your machine and `$JAVA_HOME/bin` is in your `$PATH`
## java 8 compatibility
#### Given
Note in `pom.xml` the following property:
```
1.8
```
The above property is specific to Spring boot to set both the java compiler `source` and `target` versions. For Spring Boot projects, that's all you need.
For java projects that do not use Spring Boot, you should set these maven properties:
```
1.8
1.8
```
### When
Build the project:
```
$ mvn clean package
```
### Then
Test the java version of a generated class file:
```
javap -v ./target/classes/com/eitan/bootmaventarget/HelloController.class | grep major
```
The output should be:
```
major version: 52
```
## java 11 compatibility
Edit `pom.xml` and set all properties to `11`:
```
11
11
11
```
Then, repeat the above steps:
1. Do a clean build
2. Re-run javap
3. The output should now state `major version: 55`
Again, for a Boot project, all you need is the one `java.version` property. The other two properties can be deleted. And vice versa: for a non-Boot project, `java.version` is undefined, and you should use the two `maven.compiler.source` and `maven.compiler.target` properties instead.