Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with jdk21 #11219

Merged
merged 7 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/auto-update-otel-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/build-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Increase gradle daemon heap size
run: |
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

# vaadin 14 tests fail with node 18
- name: Set up Node
Expand Down Expand Up @@ -335,7 +335,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Set up Gradle cache
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down Expand Up @@ -388,7 +388,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand All @@ -411,7 +411,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Set up Gradle cache
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Initialize CodeQL
uses: github/codeql-action/init@8f596b4ae3cb3c588a5c46780b86dd53fef16c52 # v3.25.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/owasp-dependency-check-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Increase gradle daemon heap size
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-smoke-test-fake-backend-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand All @@ -49,7 +49,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-smoke-test-servlet-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Set up Gradle cache
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Login to GitHub package registry
uses: docker/login-action@v3
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Login to GitHub package registry
uses: azure/docker-login@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-smoke-test-servlet-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Login to GitHub package registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-muzzle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@750cdda3edd6d51b7fdfc069d2e2818cf3c44f4c # v3.3.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-smoke-test-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Login to GitHub package registry
if: inputs.publish
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-test-indy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Increase gradle daemon heap size
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-test-latest-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21

- name: Increase gradle daemon heap size
run: |
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and discuss your ideas or propose the changes you wish to make.

## Building

This project requires Java 17 to build and run tests. Newer JDK's may work, but this version is used in CI.
This project requires Java 21 to build and run tests. Newer JDK's may work, but this version is used in CI.

Some instrumentations and tests may put constraints on which java versions they support.
See [Running the tests](./docs/contributing/running-tests.md) for more details.
Expand All @@ -22,7 +22,7 @@ the Sonatype OSS snapshots repository at `https://oss.sonatype.org/content/repos

### Building from source

Build using Java 17:
Build using Java 21:

```bash
java -version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.gradle.api.provider.Property

abstract class OtelJavaExtension {
abstract val minJavaVersionSupported: Property<JavaVersion>
abstract val maxJavaVersionSupported: Property<JavaVersion>

abstract val maxJavaVersionForTests: Property<JavaVersion>

Expand Down
19 changes: 17 additions & 2 deletions conventions/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ afterEvaluate {
}

// Version to use to compile code and run tests.
val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_17
val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_21

java {
toolchain {
languageVersion.set(
otelJava.minJavaVersionSupported.map { JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), DEFAULT_JAVA_VERSION.majorVersion.toInt())) }
otelJava.minJavaVersionSupported.map {
val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt()
JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), defaultJavaVersion))
}
)
}

Expand Down Expand Up @@ -69,18 +72,30 @@ tasks.withType<JavaCompile>().configureEach {
"-Xlint:-processing",
// We suppress the "options" warning because it prevents compilation on modern JDKs
"-Xlint:-options",
// jdk21 generates more serial warnings than previous versions
"-Xlint:-serial",

// Fail build on any warning
"-Werror"
)
)
val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt()
if (Math.max(otelJava.minJavaVersionSupported.get().majorVersion.toInt(), defaultJavaVersion) >= 21) {
// new warning in jdk21
compilerArgs.add("-Xlint:-this-escape")
}
}

encoding = "UTF-8"

if (name.contains("Test")) {
// serialVersionUID is basically guaranteed to be useless in tests
compilerArgs.add("-Xlint:-serial")
// when code is compiled with jdk 21 and executed with jdk 8 -parameters flag is needed to avoid
laurit marked this conversation as resolved.
Show resolved Hide resolved
// java.lang.reflect.MalformedParametersException: Invalid parameter name ""
// when junit calls java.lang.reflect.Executable.getParameters() on the constructor of a
// non-static nested test class
compilerArgs.add("-parameters")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions custom-checks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ tasks {
"--add-exports",
"jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ plugins {
id("otel.java-conventions")
}

tasks {
compileJava {
// when code is compiled with jdk 21 and executed with jdk 8 -parameters flag is needed to avoid
// java.lang.reflect.MalformedParametersException: Invalid parameter name ""
// when junit calls java.lang.reflect.Executable.getParameters() on the constructor of a
// non-static nested test class
options.compilerArgs.add("-parameters")
}
}

dependencies {
api(project(":testing-common"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void sanitizeCql(String original, String expected) {
when(exchange.getIn()).thenReturn(message);

String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(actualSanitized, expected);
assertEquals(expected, actualSanitized);
}

@ParameterizedTest
Expand All @@ -45,7 +45,7 @@ void sanitizeJdbc(String original, String expected) {
when(exchange.getIn()).thenReturn(message);

String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(actualSanitized, expected);
assertEquals(expected, actualSanitized);
}

@ParameterizedTest
Expand All @@ -60,7 +60,7 @@ void sanitizeSql(String original, String expected) {
when(exchange.getIn()).thenReturn(message);

String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(actualSanitized, expected);
assertEquals(expected, actualSanitized);
}

static class SqlArgs implements ArgumentsProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ muzzle {
}
}

if (findProperty("testLatestDeps") as Boolean) {
// when running on jdk 21 Elasticsearch53SpringRepositoryTest occasionally fails with timeout
otelJava {
maxJavaVersionSupported.set(JavaVersion.VERSION_17)
}
}

dependencies {
compileOnly("org.elasticsearch.client:transport:5.3.0") {
isTransitive = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -26,8 +24,6 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.RegisterExtension;

abstract class ExecutorInstrumentationTest<T extends ExecutorService>
Expand All @@ -51,24 +47,6 @@ static class ThreadPoolExecutorTest extends ExecutorInstrumentationTest<ThreadPo
}
}

@EnabledForJreRange(min = JRE.JAVA_21)
static class VirtualThreadExecutorTest extends ExecutorInstrumentationTest<ExecutorService> {
VirtualThreadExecutorTest() {
super(newVirtualThreadPerTaskExecutor());
}

private static ExecutorService newVirtualThreadPerTaskExecutor() {
Method newVirtualThreadPerTaskExecutor;
try {
newVirtualThreadPerTaskExecutor =
Executors.class.getMethod("newVirtualThreadPerTaskExecutor");
return (ExecutorService) newVirtualThreadPerTaskExecutor.invoke(null);
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
throw new IllegalStateException("Should not happen on Java 21+", e);
}
}
}

static class WorkStealingPoolTest extends ExecutorInstrumentationTest<ExecutorService> {
public WorkStealingPoolTest() {
super(Executors.newWorkStealingPool(2));
Expand Down
Loading
Loading