build.gradle任务根据文件名选择性地复制依赖项?

zd287kbt  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(154)

我尝试使用Kotlinfor AWS lambda with Docker,它需要复制依赖项,如“kotlin-stdlib-{version}.jar”,否则我会得到以下错误:

{"errorMessage":"kotlin/jvm/internal/Intrinsics","errorType":"java.lang.NoClassDefFoundError","stackTrace":["Handler.handleRequest(Main.kt)","java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)","java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)","java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)","java.base/java.lang.reflect.Method.invoke(Unknown Source)"],"cause":{"errorMessage":"kotlin.jvm.internal.Intrinsics. Current classpath: file:/var/task/:file:/var/task/lib/kotlin-lambda-docker-1.0-SNAPSHOT.jar","errorType":"java.lang.ClassNotFoundException","stackTrace":[]}}

我可以在build.gradle中复制它并让它工作:

tasks.register('saveDependencies', Copy) {
    configurations.each {
        if (it.isCanBeResolved()) {
            from it into "build/libs"
        }
    }
}

但这也包括类等。
我如何复制以“Kotlin”开始并以“.jar”结束的依赖项?

hec6srdp

hec6srdp1#

您可以按照文档上的指示随意使用包含/排除。下面这句话应该可以解决这个问题:

tasks.register('saveDependencies', Copy) {
    configurations.each {
        if (it.isCanBeResolved()) {
            from it include("**/kotlin/**/*.jar") into "build/libs"
        }
    }
}

相关问题