gpt4 book ai didi

gradle - 如果应用了 Gradle 插件,我如何有条件地运行代码?

转载 作者:行者123 更新时间:2023-12-04 17:43:38 29 4
gpt4 key购买 nike

我有一个我想要的脚本插件:

  • 检查 ivy-publish应用(通过 apply plugin: ivy-publish):
  • 如果适用,声明publishing { repositories { ivy { } } }
  • 如果没有应用,运行一些其他代码

  • 但是,如果 ivy-publish,我不确定如何实际运行代码。应用了插件,但我在 documentation 中找不到任何相关信息.有没有办法做到这一点?

    最佳答案

    您可以使用 PluginManager.withPlugin(String id, Action<? super AppliedPlugin> action )方法。来自 Javadoc:

    If a plugin with the specified ID has already been applied, the supplied action will be executed immediately. Otherwise, the action will executed immediately after a plugin with the specified ID is applied.



    在您的构建脚本中,您可以执行以下操作:
    pluginManager.withPlugin('ivy-publish') {
    // Do configuration
    }

    关于gradle - 如果应用了 Gradle 插件,我如何有条件地运行代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46204642/

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