|
| 1 | +# Valhalla Getting started |
| 2 | +How to get started with Valhalla Early Access builds. Installing and using with Maven. |
| 3 | + |
| 4 | +### References: |
| 5 | +https://openjdk.org/projects/valhalla/early-access |
| 6 | + |
| 7 | +### Download |
| 8 | +https://jdk.java.net/valhalla/ |
| 9 | + |
| 10 | +### (Maybe) have a directory to put it into |
| 11 | +```bash |
| 12 | +mkdir -p ~/localjdk |
| 13 | +mv ~/Downloads/openjdk-* ~/localjdk |
| 14 | +``` |
| 15 | + |
| 16 | +### Extract the tarball |
| 17 | +```bash |
| 18 | +cd ~/localjdk |
| 19 | +tar -xvf openjdk-*.tar.gz |
| 20 | +``` |
| 21 | + |
| 22 | +### MacOS Only: |
| 23 | +On macOS, after expanding the tar.gz archive, you may need to remove the quarantine attribute from the bits before commands can be executed. |
| 24 | +```bash |
| 25 | +xattr -d com.apple.quarantine ./jdk-23.jdk |
| 26 | +``` |
| 27 | + |
| 28 | +### Rename the jdk directory to something more obvious |
| 29 | +```bash |
| 30 | +mv jdk-23.jdk valhalla-23.jdk |
| 31 | +``` |
| 32 | + |
| 33 | +### SDK Man install (MacOS) |
| 34 | +```bash |
| 35 | +# the full path to the jdk is: |
| 36 | +echo $(realpath valhalla-23.jdk/Contents/Home) |
| 37 | + |
| 38 | +# install it to sdkman |
| 39 | +sdk install java 23.ea.valhalla $(realpath valhalla-23.jdk/Contents/Home) |
| 40 | + |
| 41 | +# check it ... |
| 42 | +sdk use java 23.ea.valhalla |
| 43 | +java -version |
| 44 | +``` |
| 45 | + |
| 46 | +``` |
| 47 | +❯ java -version |
| 48 | +openjdk version "23-valhalla" 2024-09-17 |
| 49 | +OpenJDK Runtime Environment (build 23-valhalla+1-90) |
| 50 | +OpenJDK 64-Bit Server VM (build 23-valhalla+1-90, mixed mode, sharing) |
| 51 | +``` |
| 52 | + |
| 53 | +### Cleanup (optional) |
| 54 | +```bash |
| 55 | +# remove the tarball |
| 56 | +rm ~/localjdk/openjdk-23-valhalla+1-90_macos-aarch64_bin.tar.gz |
| 57 | +``` |
| 58 | + |
| 59 | +### Uninstall |
| 60 | +```bash |
| 61 | +# uninstall it from sdkman |
| 62 | +sdk uninstall java 23.ea.valhalla |
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | +# Maven |
| 67 | + |
| 68 | +### enable preview features |
| 69 | +Enable preview features in the compiler plugin, surefire, failsafe, and javadoc plugin. |
| 70 | + |
| 71 | +#### surefire, failsafe, compiler plugin |
| 72 | +```xml |
| 73 | + <properties> |
| 74 | + <!-- surefire and failsafe --> |
| 75 | + <argLine>--enable-preview</argLine> |
| 76 | + <!-- compiler plugin --> |
| 77 | + <maven.compiler.release>23</maven.compiler.release> |
| 78 | + <maven.compiler.enablePreview>true</maven.compiler.enablePreview> |
| 79 | + </properties> |
| 80 | +``` |
| 81 | + |
| 82 | +#### maven-javadoc-plugin |
| 83 | +```xml |
| 84 | + <plugin> |
| 85 | + <groupId>org.apache.maven.plugins</groupId> |
| 86 | + <artifactId>maven-javadoc-plugin</artifactId> |
| 87 | + <configuration> |
| 88 | + <additionalOptions>--enable-preview</additionalOptions> <!-- Valhalla --> |
| 89 | + </configuration> |
| 90 | +</plugin> |
| 91 | +``` |
| 92 | + |
| 93 | +#### Plugins? |
| 94 | +If using maven plugins that run during the build these also might |
| 95 | +need to enable preview features. |
| 96 | + |
| 97 | +Create a file in the root of the project called `.mvn/jvm.config` and add the |
| 98 | +following line into that file: |
| 99 | +```bash |
| 100 | +--enable-preview |
| 101 | +``` |
| 102 | + |
| 103 | + |
| 104 | +# Using `value` classes |
| 105 | + |
| 106 | +### Record |
| 107 | +Most record types are good candidates for value classes. |
| 108 | +```java |
| 109 | +public value class MyRecord(String name, int age) {} |
| 110 | +``` |
| 111 | + |
| 112 | +### Value Class |
| 113 | +```java |
| 114 | +value class MyValueClass { |
| 115 | + |
| 116 | + // All fields are final |
| 117 | + private /*final*/ OtherThing dependency; |
| 118 | + |
| 119 | + MyValueClass(OtherThing dependency) { |
| 120 | + this.dependency = dependency; |
| 121 | + } |
| 122 | + ... |
| 123 | +} |
| 124 | +``` |
| 125 | +### Restrictions |
| 126 | +All fields are final and no "Identity" so: |
| 127 | +- All fields are final |
| 128 | +- No use of `synchronized` |
| 129 | +- No use of `Object.wait()` |
| 130 | +- No use of `Object.notify()` |
| 131 | +- the == operator compares value class instances according to their field values, without regard to when or where they were created |
0 commit comments