如何在IntelliJ中设置Gradle插件项目? [英] How to setup a Gradle plugin project in IntelliJ?

查看:1042
本文介绍了如何在IntelliJ中设置Gradle插件项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个独立的Gradle插件项目,如;请注意,如果此项目不符合所需的设置。

 
├──MyExamplePlugin.iml
├──build.gradle
├──gradle
│└──wrapper
│├──gradle-wrapper.jar
│└──gradle-wrapper.properties
├──gradlew
├──gradlew.bat
├──插件
│└─rcrc
│└──main
│├──groovy
││└──com
││└──example
││└──MyExamplePlugin.groovy
│└──resources
│└──META-INF
│└──gradle-plugins
│└─myexample.properties
└──settings.gradle

然后我开始实施这个类:

  import org.gradle.api.Plugin 
import org.gradle.api.Project

class MyExamplePlugin实现插件< Pr oject> {
// ...
}

问题在于 org.gradle.api。* 找不到。

解决方案

转到新的空文件夹并键入:

  gradle init  - 类型groovy-library 
然后编辑生成的build.gradle文件并添加:

 编译gradleApi()

给依赖关系,和:

  apply plugin:'idea'

到顶部附近的插件。

然后运行:

  ./gradlew idea 

然后在IntelliJ中打开生成的项目


I want to create a standalone Gradle plugin project as described in the Gradle documentation. I would like to use IntelliJ with code completion for Groovy and Gradle. Since there is no specialized wizard to create a Gradle plugin project I have to do it manually.
I already managed to add the Groovy SDK (binary) in the IDE via: File / Other Settings / Default Project Structure as shown in the screenshot.

To start with I created a new Gradle project which also contains the Gradle wrapper. I then create a Groovy script named MyExamplePlugin.groovy following the project structure of the sdk-manager-plugin; please note me if this project does not follow the desired setup.

.
├── MyExamplePlugin.iml
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── plugin
│   └── src
│       └── main
│           ├── groovy
│           │   └── com
│           │       └── example
│           │           └── MyExamplePlugin.groovy
│           └── resources
│               └── META-INF
│                   └── gradle-plugins
│                       └── myexample.properties
└── settings.gradle

Then I start implementing the class:

import org.gradle.api.Plugin
import org.gradle.api.Project

class MyExamplePlugin implements Plugin<Project> {
   // ...
}

The problem is that org.gradle.api.* cannot be found.

解决方案

Go to a new, empty folder and type:

gradle init --type groovy-library

Then edit the generated build.gradle file and add:

compile gradleApi()

To the dependencies, and:

apply plugin: 'idea'

To the plugins near the top.

Then run:

./gradlew idea

And open the generated project in IntelliJ

这篇关于如何在IntelliJ中设置Gradle插件项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆