How to setup a Gradle plugin project in IntelliJ?

我们两清 提交于 2019-12-20 10:40:17

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/28436365/how-to-setup-a-gradle-plugin-project-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!