我在从外部 Gradle 脚本文件应用时遇到插件导入错误。 例如: 在文件 gradle/lambda.gradle 中:
apply plugin: 'base'
apply plugin: 'jp.classmethod.aws.lambda'
import com.amazonaws.services.lambda.model.InvocationType;
import jp.classmethod.aws.gradle.lambda.AWSLambdaDeleteFunctionTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaInvokeTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaPublishVersionTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaCreateAliasTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaUpdateAliasTask;
import jp.classmethod.aws.gradle.lambda.VpcConfigWrapper
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "jp.classmethod.aws:gradle-aws-plugin:0.38"
}
}
在 build.gradle 文件中,我通过以下方法应用外部脚本:
apply from: 'gradle/lambda.gradle'
但是它会产生关于插件导入的错误:
Plugin with id 'jp.classmethod.aws.lambda' not found.
可以通过在 build.gradle 文件中包含相同的 buildscript 代码块来解决这个问题。
这个问题的根本原因是什么? 实现这一目标的推荐方法是什么?
最佳答案
基于my answer here ,你应该这样做:
What you can do on the other hand is to put your
buildscript
block into thebuild.gradle
file of the root project and then all other build files from subprojects will inherit this block.
编辑:由于导入而无法工作。 gradle/lambda.gradle
中需要 classpath "jp.classmethod.aws:gradle-aws-plugin:0.38"
来解析 import
,build.gradle
中也需要它,因为插件 jp.classmethod.aws.lambda
从此处应用(通过 apply from
)
关于java - 如何导入外部 gradle 脚本文件并在 Gradle 中正确导入插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49838462/