I have a maven project which runs normally on my local computer, but when I push the code to the cloud repository, it fails in Cloud Build with the error below:
Step #0: [ERROR] COMPILATION ERROR :
Step #0: [INFO] -------------------------------------------------------------
Step #0: [ERROR] javac: invalid target release: 11
Step #0: Usage: javac <options> <source files>
Step #0: use -help for a list of possible options
Step #0:
Step #0: [INFO] 1 error
Step #0: [INFO] -------------------------------------------------------------
Step #0: [INFO] ------------------------------------------------------------------------
Step #0: [INFO] BUILD FAILURE
Step #0: [INFO] ------------------------------------------------------------------------
Step #0: [INFO] Total time: 18.785 s
Step #0: [INFO] Finished at: 2023-05-03T05:52:33Z
Step #0: [INFO] ------------------------------------------------------------------------
Step #0: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project job: Compilation failure
Step #0: [ERROR] javac: invalid target release: 11
Step #0: [ERROR] Usage: javac <options> <source files>
Here is my pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ddd.dd</groupId>
<artifactId>job</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>jar</packaging>
<name>job</name>
<description>project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version>
</properties>
<dependencies>
<!-- spring-boot-starter-web (spring-webmvc + tomcat) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<!-- job-core -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.1.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/ob_core-2.1.0.jar</systemPath>
</dependency>
<!-- kml -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.5</version>
</dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.2.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>10.0.22</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.5.RELEASE</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>map.job.executor.JobExecutorApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/mybatis/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-generator</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<excludes>
<exclude>**/*Test.java</exclude>
<exclude>**/Test*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
In the project structure (intellij idea) I've selected Java 11 (oracle) as SDK, in the modules -> dependencies I have done same. In the settings -> compiler, I selected java compiler and target bytecode as 11. Also $JAVA_HOME is : /usr/lib/jvm/jdk-11. It runs on my local machine, however build fails in Cloud Build with the above error once I push my code.
Here is the Dockerfile
:
FROM openjdk:11
WORKDIR /job
ADD ./target/xxxx-1.0.0-RELEASE.jar /job
EXPOSE 22 9999
ENV NAME job
CMD ["java","-jar", "-Duser.timezone=Australia/Sydney", "xxxx-1.0.0-RELEASE.jar"]
This is my cloudbuild.yaml
file:
steps:
# build the container image
- name: 'gcr.io/cloud-builders/mvn'
args: ['install', '-Dmaven.test.skip=true']
# build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/xxxx-$_NAMESPACE:$BUILD_ID', '.']
- name: "gcr.io/cloud-builders/gcloud"
entrypoint: 'bash'
args:
- '-c'
- |
for image_name in $(gcloud container images list); do
for digest in $(gcloud container images list-tags $image_name --format=json | awk '/digest/{ print $2 }' | sed -e 's/^"//' -e 's/.\{2\}$//' | tail -n +6); do
gcloud container images -q delete $image_name@$digest --force-delete-tags;
done;
done;
# push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/xxxx-$_NAMESPACE:$BUILD_ID']
# Deploy container image to Cloud Run
- name: "gcr.io/cloud-builders/gcloud"
entrypoint: 'bash'
args:
- '-c'
- |
gcloud container clusters get-credentials oni-cluster --zone australia-southeast1-b
sed -i.bak 's#IMAGE_PLACEHOLDER#gcr.io/$PROJECT_ID/xxxx-$_NAMESPACE:$BUILD_ID#' ./k8s/sync/*.yaml
sed -i.bak 's#NAMESPACE_PLACEHOLDER#$_NAMESPACE#' ./k8s/sync/*.yaml
kubectl --namespace=$_NAMESPACE apply -f k8s/sync/
images:
- gcr.io/$PROJECT_ID/xxxx-$_NAMESPACE:$BUILD_ID