How to change the default Cloud Composer Java version

Problem

You are trying to use Cloud Composer to run Java 11 JARs, but Airflow tasks only support Java 8. How can you change the default Cloud Composer Java to version 11 and above?

The following log is obtained when running the Java 11 compiled JAR: 

Error: A JNI error has occurred, please check your installation and try again\nException in thread "main" java.lang.UnsupportedClassVersionError: <REDACTED> 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

Environment

  • Cloud composer

Solution

  1. Use the DataflowTemplateOperator instead of the DataFlowJavaOperator. 
  2. Use KubernetesPodOperator and create a Docker image with Google Cloud and Java 11.
Note: The DataFlowJavaOperator requires Java to be locally installed in order to prepare artifacts, while with DataflowTemplateOperator, Dataflow templates guarantee that the version of JARs is exactly the same between executions.