Abhishek Solanki
Abhishek Solanki

Reputation: 426

Issue with Google App Engine Flexible Environment using Java 11 as Runtime in terraform code

I am trying to configure a Google App Engine Flexible Environment for my Java application, and I want to use Java 11 as the runtime. However, I'm encountering an issue where it seems to be using Java 8 instead, and I'm getting the following error:

google_app_engine_flexible_app_version.myapp_v1: Still creating... [3m30s elapsed]╷│ Error: Error waiting to create FlexibleAppVersion: Error waiting for Creating FlexibleAppVersion: Error code 9, message: An internal error occurred while processing task /app-engine-flex/flex_await_healthy/flex_await_healthy>2023-10-27T03:35:51.497Z43727.vt.2: Start command: java -showversion -Xms491M -Xmx491M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -jar app.jar
│ -XX:InitialHeapSize=514850816 -XX:MaxHeapSize=514850816 -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC 
│ openjdk version "1.8.0_345"
│ OpenJDK Runtime Environment (Temurin)(build 1.8.0_345-b01)
│ OpenJDK 64-Bit Server VM (Temurin)(build 25.345-b01, mixed mode)
│ │ Error: A JNI error has occurred, please check your installation and try again
│ Exception in thread "main" java.lang.UnsupportedClassVersionError: com/example/appengine/Application has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
│       at java.lang.ClassLoader.defineClass1(Native Method)
│       at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
│       at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
│       at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
│       at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
│       at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
│       at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
│       at java.security.AccessController.doPrivileged(Native Method)
│       at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
│       at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
│       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
│       at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
│       at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)

I've configured my google_app_engine_flexible_app_version resource like this: This time I have tried using app.yaml file from terraform resource

resource "google_app_engine_flexible_app_version" "myapp_v1" {
  version_id = "v1"
  project    = "fresh-test1"
  service    = "servcie1"
  runtime    = "java"

  deployment {
    files {
      name = "micronaut-helloworld-0.1.jar"
      source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}"
    }
    cloud_build_options {
      app_yaml_path = "[./app.yaml]"
    }
  }

  liveness_check {
    path = "/"
  }

  readiness_check {
    path = "/"
  }

  env_variables = {
    port = "8080"
  }

  automatic_scaling {
    cool_down_period = "120s"
    max_total_instances = 2
    min_total_instances = 1
    cpu_utilization {
      target_utilization = 0.5
    }
  }
  delete_service_on_destroy = true
  service_account = google_service_account.custom_service_account.email
}

app.yaml

runtime: java
env: flex
runtime_config:
  operating_system: ubuntu22
  runtime_version: 11
service: api
handlers:
- url: /.*
  script: this field is required, but ignored

resources:
  cpu: 1
  memory_gb: 4
  disk_size_gb: 40

automatic_scaling:
  min_num_instances: 1
  max_num_instances: 1

  cpu_utilization:
    target_utilization: 0.85

env_variables:
  SPRING_PROFILES_ACTIVE: prod
  

I am running the terraform code from google cloud shell. and Java --version points to java17 JAVA_HOME points to java11 I don't know if that matters.

Is there a way to properly configure Google App Engine Flexible Environment to use Java 11 as the runtime? Am I using the correct entrypoint and runtime configuration? Any help or guidance would be greatly appreciated.

Upvotes: 1

Views: 493

Answers (1)

Antonio
Antonio

Reputation: 1

I have the same error.

I have a Spring Boot application and I migrated my project from Java 8 to Java 17, and I could deploy normally on october 14. I could see in the logs that the app is running on Java 17.

On october 15, I just added a small feature, with no changes in the configuration, and then I started to get the same error.

As I didn't change the configuration, I suppose it is a problem on Google Cloud, but it's been happening for me since october 15.

Here's my app.yaml, made following Google Cloud tutorial:

runtime: java
env: flex
runtime_config:
  operating_system: ubuntu22
  runtime_version: 17
  
service: api
  
handlers:
- url: /.*
  script: this field is required, but ignored
  
resources:
  cpu: 1
  memory_gb: 4
  disk_size_gb: 40


automatic_scaling:
  min_num_instances: 1
  max_num_instances: 1
  
  cpu_utilization:
    target_utilization: 0.85
  
env_variables:                      
    SPRING_PROFILES_ACTIVE: prod

Upvotes: 0

Related Questions