java enable preview

Enabling preview features is not without consequence. There are some configuration to do.

Build

Maven compiler

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven-compiler-plugin.version}</version>
    <configuration>
        <enablePreview>true</enablePreview>
    </configuration>
</plugin>

Maven surefire

If you are using sonarqube / Jacoco for code coverage, you might need to add the following:

<properties>
    <argLine>--enable-preview</argLine>
</properties>

⚠️ Do not add to maven-surefire-plugin configuration! Because Jacoco is also adding some arguments:

09:16:09 [INFO] --- jacoco:0.8.12:prepare-agent (prepare-agent) @ bootstrap ---
09:16:09 [INFO] argLine set to -javaagent:/home/l-lin/.m2/repository/org/jacoco/org.jacoco.agent/0.8.12/org.jacoco.agent-0.8.12-runtime.jar=destfile=/home/l-lin/work/preventive-continuous-care/bootstrap/target/jacoco.exec --enable-preview

Run

Run java app

Add the flag --enable-preview when running the jar file:

java --enable-preview -jar app.jar

datadog

This structured concurrency is supported in dd-java-agent version 1.35.0-RC1:

✨🧹 Improve loom features support (DataDog/dd-trace-java#7045)

The class that supports the structured concurrency instrumentation: StructuredTaskScopeInstrumentation.java.