本文介绍了应用 gradle 自定义 jar 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 gradle 创建了一个简单的基于 groovy 的插件.

I've created a simple groovy-based plugin for gradle.

在我的 gradle.build 文件中,我有以下内容:

in my gradle.build file I have the following:

apply plugin: 'groovy'

dependencies {
    compile gradleApi()
    compile localGroovy()
}

一切都很好,我得到了一个构建目录,并且在 lib 文件夹中生成了一个 .jar,我猜这是一个独立的插件.

Everything works great, I get a build directory and a .jar is generated in the lib folder, I guess this is the standalone plugin.

现在我想知道如何将这个新插件注册到我的 gradle 安装中,这样我就可以了应用插件:'myPlugin' 我做了以下事情:

Now I want to know how to register this new plugin into my gradle instalation, so I can doapply plugin: 'myPlugin' I've done the following:

  • 将插件放入安装中的插件文件夹
  • 创建 myplugin.properties 文件并将其包含在 META-INF 文件夹中
  • 将相同的属性文件放在 src 目录的 META-INF 中(绝望的行为)

在我尝试应用插件的每一步之后,我都会收到错误:

Well after every step when I try to apply the plugin I get the error:

  • 未找到 ID 为myplugin"的插件

我怎样才能做到这一点??

How can I get this right??

您能否列出使我的插件正常工作的步骤列表?(我是 gradle+groovy 的新手)

can you state a list of steps that will get my plugin working? (Im new to gradle+groovy)

感谢您的帮助

推荐答案

用户指南的第 58 章 包含您需要的所有信息.总结:

The chapter 58 of the user guide has all the information you need. In summary:

  • 将您的 myPlugin.properties 放在您的项目结构中,在 src/main/resources/META-INF/gradle-plugins/
  • 像往常一样构建你的罐子
  • 在您希望使用此插件的脚本中,添加一个 buildscript 闭包,例如:

  • Put your myPlugin.properties inside your project structure, in src/main/resources/META-INF/gradle-plugins/
  • Build your jar like you usually do
  • In the script you wish to use this plugin, add a buildscript closure to something like:

buildscript {
    repositories {
        flatDir dirs: "build/libs"
    }
    dependencies {
        classpath "your.group:your-plugin:1.0.0"
    }
}

或者任何你希望的 repositoriesdependencies 设置,但是你需要使用 classpath 配置,就像我在这里所做的那样.我认为您不能(或应该!)像您那样将 jar 添加到 Gradle 的插件目录中.

Or whatever settings for repositories and dependencies you wish, but you need to use the classpath configuration as I've done here. I don't think you can (or should!) add the jar to the plugin dir of Gradle like you did.

注意: flatDir 不解决传递依赖.依赖管理的相同规则适用于构建脚本,因此您可以使用常规的 maven 或 ivy 存储库来部署您的插件.

Note: the flatDir does not resolve transitive dependencies. The same rule for dependency management applies to the buildscript, so you can use a regular maven or ivy repository to deploy your plugin.

这篇关于应用 gradle 自定义 jar 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:27
查看更多