Skip to content

Commit

Permalink
Add Java8 support (#353)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
psx95 committed Jun 26, 2024
1 parent 11c85b9 commit 44da9c4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 26 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Provides OpenTelemetry Exporters for Google Cloud Operations.

## Building

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

```
$ ./gradlew test
Expand Down
27 changes: 18 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ subprojects {
group = "com.google.cloud.opentelemetry"
// Note: Version now comes from nebula plugin

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
mavenLocal()
Expand All @@ -103,6 +100,24 @@ subprojects {
archivesBaseName = "${project.name}"
}

// Support for some higher language versions can only be achieved using Toolchains.
// Compatibility matrix at https://docs.gradle.org/current/userguide/compatibility.html#java
// See https://docs.gradle.org/current/userguide/toolchains.html#toolchains
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

// This ensures bytecode compatibility with Java 8 by ensuring that symbols not
// available in Java 8 are not used in the source code.
// This is equivalent of setting --release flag in Java compiler introduced in Java 9.
// Note that the toolchain used is Java 11 - which means Java 11 is required
// to build this project.
compileJava {
it.options.release = 8
}

// Include license check and auto-format support.
spotless {
java {
Expand Down Expand Up @@ -234,12 +249,6 @@ subprojects {
archives javadocJar, sourcesJar
}

javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

java {
withJavadocJar()
withSourcesJar()
Expand Down
6 changes: 0 additions & 6 deletions detectors/resources-support/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ dependencies {
testRuntimeOnly(testLibraries.junit5_runtime)
}

afterEvaluate {
tasks.named("compileJava"){
options.release = 8
}
}

test {
// required for discovering JUnit 5 tests
useJUnitPlatform()
Expand Down
6 changes: 0 additions & 6 deletions detectors/resources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
*/
description = 'Google Cloud resource provider for OpenTelemetry'

afterEvaluate {
tasks.named("compileJava"){
options.release = 8
}
}

dependencies {
implementation(libraries.opentelemetry_api)
implementation(libraries.opentelemetry_sdk)
Expand Down
5 changes: 4 additions & 1 deletion e2e-test-server/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# End to End tests

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


## Building a Docker image.

From the *root* directory of the projet, run:
From the *root* directory of the project, run:

```
docker build . --file=e2e.Dockerfile
Expand Down
8 changes: 8 additions & 0 deletions e2e-test-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ application {
mainClass.set('com.google.cloud.opentelemetry.endtoend.Server')
}

// Java 11 required to build this module since it has a dependency on Cloud Functions.
// Cloud Functions (Gen2) have Java 11 minimum requirement.
compileJava{
// This is only possible since the toolchain guarantees Java 11 presence.
// Toolchain is set in the root build.gradle file.
it.options.release = 11
}

description = 'End-To-End integration testing server'

shadowJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -167,7 +167,7 @@ private Attributes instrumentationLibraryLabels(
instrumentationScopeInfo.getName())
.put(
AttributeKey.stringKey(LABEL_INSTRUMENTATION_VERSION),
Objects.requireNonNullElse(instrumentationScopeInfo.getVersion(), ""))
Optional.ofNullable(instrumentationScopeInfo.getVersion()).orElse(""))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

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

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

private static InternalTraceExporter createWithClient(
Expand Down

0 comments on commit 44da9c4

Please sign in to comment.