【问题标题】:only build script and other plugins script blocks are allowed before plugins在插件之前只允许构建脚本和其他插件脚本块
【发布时间】:2023-03-08 15:31:02
【问题描述】:

我想使用具有这种语法的 gradle 插件

 plugins {
  id "id" version "version"
}

但我有错误

only build script and other plugins script blocks are allowed before plugins 

我将它移到 bloc buildscript 但仍然无法正常工作。

我怎样才能应用这种插件?

这是我想要包含在我的项目中的插件

gradle git properties plugin

这是我的 gradle 版本的输出

    Gradle 4.3.1
------------------------------------------------------------

Build time:   2017-11-08 08:59:45 UTC
Revision:     e4f4804807ef7c2829da51877861ff06e07e006d

Groovy:       2.4.12

【问题讨论】:

    标签: gradle plugins


    【解决方案1】:

    每当您编写build.gradle 脚本并使用新的plugins 脚本块时,您需要将其作为文件中的第一个块。此规则的唯一例外是其他 plugins 块或特殊的 buildScript 块,它们始终必须先行。

    例如,这个脚本很好:

    plugins {
        // ...
    }
    
    dependencies {
        // ...
    }
    

    这个也不错:

    buildScript {
        // ...
    }
    
    plugins {
        // ...
    }
    
    repositories {
        // ...
    }
    

    但是这个无效:

    repositories {
         // ...
    }
    
    plugins {
        // ...
    }
    

    【讨论】:

    • 第一个场景怎么可能?!在根build.gradledependencies {buildscript {里面,你说要解决这个错误,我们应该设置plugins { after buildScript {`和dependencies {之前
    • dependencies 块内的 buildscript 块与常规 dependencies 块不同。此外,这与项目是否为根项目完全无关。
    • 你做到了!好建议!
    【解决方案2】:

    构建文件 'C:\androidProjelerim\ZozoTagram\build.gradle' 行:24

    无法编译构建文件“C:\androidProjelerim\ZozoTagram\build.gradle”。

    启动失败: build file 'C:\androidProjelerim\ZozoTagram\build.gradle': 24: 只有 buildscript {}、pluginManagement {} 和其他 plugins {} 脚本块允许在 plugins {} 块之前,不允许其他语句

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案3】:

    我只是通过删除解决了这个问题。

    task clean(type: Delete) { delete rootProject.buildDir }

    【讨论】:

    • 说 tasl clean 已经存在是行不通的
    猜你喜欢
    • 2020-09-22
    • 2023-02-19
    • 2023-02-19
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 2023-01-12
    • 2012-04-05
    • 1970-01-01
    相关资源
    最近更新 更多