2

Java 19 has new features: virtual threads (as preview) and structured concurrency (as incubator). Gradle 7.6 will support Java 19. Given that 7.6-rc-1 is available, how can I try out these new features? I have working Bash scripts like the following:

compile:

javac --release 19 --enable-preview \
--add-modules jdk.incubator.concurrent \
-cp $CLASSPATH \
[snip]

run:

java --enable-preview \
-cp $CLASSPATH \
--add-modules jdk.incubator.concurrent \
net.codetojoy.Runner

How are these flags translated into Gradle?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Michael Easter
  • 23,733
  • 7
  • 76
  • 107

1 Answers1

3

Consider this build.gradle file:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = "net.codetojoy.Runner"

compileJava {
    options.compilerArgs.addAll(['--release', '19']) 
    options.compilerArgs.addAll(['--enable-preview'])
    options.compilerArgs.addAll(['--add-modules', 'jdk.incubator.concurrent'])
}

application {
    applicationDefaultJvmArgs = ['--enable-preview', 
                                 '--add-modules', 'jdk.incubator.concurrent']
}

Here is a working example, which uses the Gradle wrapper for 7.6-rc-1, and illustrates structured concurrency.

Michael Easter
  • 23,733
  • 7
  • 76
  • 107