首页 文章

Gradle 'apply from:'抛出异常

提问于
浏览
0

我在build.gradle脚本中使用'apply from:' . apply的用法发生在我的自定义插件中 . 以前有其他人遇到这样的问题吗?

apply from: '../directory/' + chosenSubDir + '/build.gradle'

我收到以下异常:

java.util.LinkedHashMap cannot be cast to org.gradle.api.Project

我的观点是从正确的文件(也是build.gradle)中获取所有部分,并将它们分配给将存储此数据的辅助类的字段 .

编辑:目前,整个代码都在build.main脚本中,但最终会分裂 .

class MyPlugin implements Plugin<Project> {
    project.extensions.create('myFile', HelperClass)

    project.task('task') {
        doLast {
           //listing files

           //choosing file by user

           //here receiving an exception \/
           apply from: '../DirWithFiles/' + chosenFile

           //further operations with content of chosen file
        }
    }
}

class HelperClass {
    def config = {
        set {}
        map {}
        //etc..
    }
}

apply plugin: MyPlugin

我通过调用./gradlew任务来调用我的插件

1 回答

  • -1

    正如Opal建议的那样,我使用'project.apply from'而不是'apply from',它现在运行正常 . 谢谢!

相关问题