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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With