gpt4 book ai didi

java - zip文件太大aws lambda java gradle

转载 作者:行者123 更新时间:2023-12-03 06:27:01 28 4
gpt4 key购买 nike

我想在AWS Lambda上部署我的Java函数

我拿了这份文档https://docs.aws.amazon.com/lambda/latest/dg/java-package.html

这是我的build.gradle文件

plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
}

group 'com.xxx'
version '1.0'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains:annotations:16.0.2"
implementation 'com.amazonaws:aws-lambda-java-core:1.2.0'
implementation 'com.amazonaws:aws-lambda-java-events:2.2.7'
implementation 'com.google.code.gson:gson:2.8.6'

compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.2'

runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.1.0'

testCompile group: 'junit', name: 'junit', version: '4.12'
}

jar {
manifest {
attributes 'Main-Class': 'Main'
}
}

task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': archiveVersion,
'Main-Class': 'Main'
}
baseName = project.name + '-all'
from sourceSets.main.output

dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
with jar
}

task buildZip(type: Zip) {
manifest {
attributes (
'Implementation-Title': 'AWS Handler',
'Implementation-Version': archiveVersion,
'Main-Class': 'AWSHandler'
)
}

from compileJava
from processResources
into('lib') {
from configurations.runtimeClasspath
}
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}


所以我正在运行 gradle buildZip来构建我的zip,实现 RequestHandler的aws类在 src/main/java/AWSHandler.java

命令成功结束后,我有一个710MB的zip文件,这真是太棒了!
解压缩文件时,我可以看到有很多库可以支持许多操作系统

enter image description here

传递此文档 https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html似乎在 Amazon Linux上运行了Java8函数

所以我可以清洁我的 zipper ,只得到这个操作系统

我可以用gradle来做吗,还是应该创建一个额外的脚本来清理文件?

最佳答案

into任务类型的Zip方法可以接受CopySpec,可用于添加排除项:

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Zip.html#org.gradle.api.tasks.bundling.Zip:into(java.lang.Object,%20org.gradle.api.Action)

into('lib') {
from configurations.runtimeClasspath
exclude("**windows**") // example, untested.
}

有关更多详细信息,请参见Javadoc: https://docs.gradle.org/current/javadoc/org/gradle/api/file/CopySpec.html

关于java - zip文件太大aws lambda java gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61581119/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com