Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup a Gradle plugin project in 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.

IntelliJ / Project Structure

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.

like image 336
JJD Avatar asked Feb 10 '15 16:02

JJD


People also ask

How do I create a Gradle project in IntelliJ?

On the welcome screen, click New Project. On the page that opens, let's specify our project's name (FizzBuzz) and the location. Let's select the Java option, which is what we need for our project and Gradle since we are creating a Gradle project. IntelliJ IDEA automatically adds a project SDK (JDK) in the JDK field.

How do I enable Gradle in IntelliJ?

in the Gradle tool window. Alternatively, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Build, Execution, Deployment |Build Tools |Gradle. On the Gradle page, from the Build and run using list, select Intellij IDEA.

How do I run a plugin in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Plugins. and then click Install Plugin from Disk…. Select the plugin archive file and click OK. Click OK to apply the changes and restart the IDE if prompted.


1 Answers

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

like image 170
tim_yates Avatar answered Oct 10 '22 10:10

tim_yates