0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

sam initでjava17環境!

Last updated at Posted at 2023-07-09

2023年4月末でAWSでJava17の環境を用意ができた。

なので、sam init でjava17環境を選べるようになった!

Java17.jpg

生成されたtemplate.yamlに Runtime: java17 があることがわかる。

Screenshot 2023-07-09 at 17.41.50.png

ローカルではビルドでき ~/.gradlew build など成功する筈。

% java --version
openjdk 17.0.7 2023-04-18
IBM Semeru Runtime Open Edition 17.0.7.0 (build 17.0.7+7)
Eclipse OpenJ9 VM 17.0.7.0 (build openj9-0.38.0, JRE 17 Mac OS X amd64-64-Bit Compressed References 20230418_450 (JIT enabled, AOT enabled)
OpenJ9   - d57d05932
OMR      - 855813495
JCL      - 9d7a231edbc based on jdk-17.0.7+7)


% echo $JAVA_HOME
/Users/ignacio/.sdkman/candidates/java/current

% cd HelloWorldFunction; ./gradlew build; cd ..     
Starting a Gradle Daemon, 2 incompatible Daemons could not be reused, use --status for details

BUILD SUCCESSFUL in 9s
4 actionable tasks: 4 executed

% sam build
...
Build Succeeded

失敗した場合

gradlew build単独で成功するが sam buildが失敗することがある。

% sam build
Starting Build use cache                                                                                                                                                          
Cache is invalid, running build and copying resources for following functions (HelloWorldFunction)                                                                                
Building codeuri: /Users/ignacio/Documents/code/nacho/aws-lambda/assignment-2l/HelloWorldFunction runtime: java17 metadata: {} architecture: x86_64 functions: HelloWorldFunction 
/Users/ignacio/Documents/code/nacho/aws-lambda/assignment-2l/HelloWorldFunction/gradlew is using a JVM with major version 20 which is newer than 17 that is supported by AWS      
Lambda. The compiled function code may not run in AWS Lambda unless the project has been configured to be compatible with Java 17 using 'targetCompatibility' in Gradle.          
Running JavaGradleWorkflow:GradleBuild                                                                                                                                            

Build Failed
Error: JavaGradleWorkflow:GradleBuild - Gradle Failed: FAILURE: Build failed with an exception.

* What went wrong:
Could not open cp_init generic class cache for initialization script '/var/folders/8m/h4r394gd1cg67z5g5whq0cjh0000gn/T/tmp6ee80m4a/lambda-build-init.gradle' (/Users/ignacio/.gradle/caches/7.3.3/scripts/ac0qs36aeafdloj2i01vxlr44).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 64

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 734ms

理由 gradle-wrapper.properties ファイルに記入されているgradle のバージョンが少し古めだから。 https://services.gradle.org/distributions/ にアクセスし、新めなものを選べばいい (2023年7月時点では8.1.1は良さそうだ)

-distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip

参考リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?