Skip to content

Commit 44da9c4

Browse files
authored
Add Java8 support (#353)
* Switch the default build for subprojects to Java 8 All submodules for the project now target Java 8 as the minimum supported version. Some operations module like e2e-testing still use Java 11 due to dependency constraints * Make detector-resources compatible with Java8 * Make exporter-trace compatible with Java 8 * Make exporter-metrics compatible with Java 8 * Make propagators-gcp compatible with Java 8 * Make shared-resourcemapping compatible with Java 8 * fix style issues with spotless * fix typo * Update docker image to include JDK 8 The docker image used in e2e tests requires JDK8 to compile and build trace exporter and gcp propagators. JDK8 is explicitly required because the builds of these artifacts are configured using toolchains. * Set language version in root project to Java 11 Setting the language version in root project to 11 avoids the need of having multiple JDKs to build all artifacts in this project. Java 8 bytecode compatibility is ensured using --release flag in Java compiler available starting Java 9. * Additional JDK 8 installaion no longer required * Add comment explaining need for Java 11 * Revert changes to make tests compatible with Java 8 * Java 11 not required to Run this example Java 11 specific APIs were only used in tests. * Update README to indicate Java version compatibility * Feedback: remove afterEvaluate and use singletonMap
1 parent 11c85b9 commit 44da9c4

File tree

8 files changed

+39
-26
lines changed

8 files changed

+39
-26
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ Provides OpenTelemetry Exporters for Google Cloud Operations.
66

77
## Building
88

9-
This project requires a mock server for Google Cloud APIs. To build and test, do the following:
9+
> [!IMPORTANT]
10+
> This project requires Java 11 to build and test. All artifacts published from this project support Java 8 or higher, unless otherwise noted.
11+
12+
This project requires a mock server for Google Cloud APIs. To build and test, do the following:
1013

1114
```
1215
$ ./gradlew test

build.gradle

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ subprojects {
8585
group = "com.google.cloud.opentelemetry"
8686
// Note: Version now comes from nebula plugin
8787

88-
sourceCompatibility = JavaVersion.VERSION_11
89-
targetCompatibility = JavaVersion.VERSION_11
90-
9188
repositories {
9289
mavenCentral()
9390
mavenLocal()
@@ -103,6 +100,24 @@ subprojects {
103100
archivesBaseName = "${project.name}"
104101
}
105102

103+
// Support for some higher language versions can only be achieved using Toolchains.
104+
// Compatibility matrix at https://docs.gradle.org/current/userguide/compatibility.html#java
105+
// See https://docs.gradle.org/current/userguide/toolchains.html#toolchains
106+
java {
107+
toolchain {
108+
languageVersion = JavaLanguageVersion.of(11)
109+
}
110+
}
111+
112+
// This ensures bytecode compatibility with Java 8 by ensuring that symbols not
113+
// available in Java 8 are not used in the source code.
114+
// This is equivalent of setting --release flag in Java compiler introduced in Java 9.
115+
// Note that the toolchain used is Java 11 - which means Java 11 is required
116+
// to build this project.
117+
compileJava {
118+
it.options.release = 8
119+
}
120+
106121
// Include license check and auto-format support.
107122
spotless {
108123
java {
@@ -234,12 +249,6 @@ subprojects {
234249
archives javadocJar, sourcesJar
235250
}
236251

237-
javadoc {
238-
if(JavaVersion.current().isJava9Compatible()) {
239-
options.addBooleanOption('html5', true)
240-
}
241-
}
242-
243252
java {
244253
withJavadocJar()
245254
withSourcesJar()

detectors/resources-support/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ dependencies {
2424
testRuntimeOnly(testLibraries.junit5_runtime)
2525
}
2626

27-
afterEvaluate {
28-
tasks.named("compileJava"){
29-
options.release = 8
30-
}
31-
}
32-
3327
test {
3428
// required for discovering JUnit 5 tests
3529
useJUnitPlatform()

detectors/resources/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
*/
1616
description = 'Google Cloud resource provider for OpenTelemetry'
1717

18-
afterEvaluate {
19-
tasks.named("compileJava"){
20-
options.release = 8
21-
}
22-
}
23-
2418
dependencies {
2519
implementation(libraries.opentelemetry_api)
2620
implementation(libraries.opentelemetry_sdk)

e2e-test-server/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# End to End tests
22

3+
> [!NOTE]
4+
> This module requires at least Java 11 to run.
5+
36
A set of end to end integration tests. These are run inside various environments to ensure
47
GCP automagiks work and data flows into google cloud.
58

69

710
## Building a Docker image.
811

9-
From the *root* directory of the projet, run:
12+
From the *root* directory of the project, run:
1013

1114
```
1215
docker build . --file=e2e.Dockerfile

e2e-test-server/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ application {
2323
mainClass.set('com.google.cloud.opentelemetry.endtoend.Server')
2424
}
2525

26+
// Java 11 required to build this module since it has a dependency on Cloud Functions.
27+
// Cloud Functions (Gen2) have Java 11 minimum requirement.
28+
compileJava{
29+
// This is only possible since the toolchain guarantees Java 11 presence.
30+
// Toolchain is set in the root build.gradle file.
31+
it.options.release = 11
32+
}
33+
2634
description = 'End-To-End integration testing server'
2735

2836
shadowJar {

exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/AggregateByLabelMetricTimeSeriesBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import java.util.HashMap;
4040
import java.util.List;
4141
import java.util.Map;
42-
import java.util.Objects;
42+
import java.util.Optional;
4343
import java.util.function.Predicate;
4444
import java.util.stream.Collectors;
4545

@@ -167,7 +167,7 @@ private Attributes instrumentationLibraryLabels(
167167
instrumentationScopeInfo.getName())
168168
.put(
169169
AttributeKey.stringKey(LABEL_INSTRUMENTATION_VERSION),
170-
Objects.requireNonNullElse(instrumentationScopeInfo.getVersion(), ""))
170+
Optional.ofNullable(instrumentationScopeInfo.getVersion()).orElse(""))
171171
.build();
172172
}
173173

exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/InternalTraceExporter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.io.IOException;
3939
import java.util.ArrayList;
4040
import java.util.Collection;
41+
import java.util.Collections;
4142
import java.util.List;
4243
import java.util.Map;
4344

@@ -53,7 +54,8 @@ class InternalTraceExporter implements SpanExporter {
5354
private final TraceTranslator translator;
5455

5556
private static final Map<String, String> HEADERS =
56-
Map.of("User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION);
57+
Collections.singletonMap(
58+
"User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION);
5759
private static final HeaderProvider HEADER_PROVIDER = () -> HEADERS;
5860

5961
private static InternalTraceExporter createWithClient(

0 commit comments

Comments
 (0)