IntelliJ IDEA gradle project setup

2019-07-06 03:26发布

问题:

What is the best procedure for beginning a new Gradle project in IntelliJ IDEA 12.1.3?

I created a skeleton build.gradle file with the idea plugin to generate the project files:

apply plugin: 'java'
apply plugin: 'idea'

task wrapper(type: Wrapper) {
    gradleVersion = '1.6'
}

When I open the new project IntelliJ complains that the Groovy SDK is not configured for module:

After configuring the Groovy SDK I get Java inspection issues in the build file:

Am I doing something wrong or is this normal for a Gradle based project in IDEA? Should I just disable inspection?


UPDATE

I was able to import a skeleton project and IDEA automatically configured everything properly. However I am still receiving Java inspection errors in build.gradle as shown above.

回答1:

If you use Gradle's idea task to generate project files, this is normal, as there is no way to tell IDEA what the class path of the build script itself is. If you instead use IDEA's Gradle integration ("Import from Gradle model"), this problem doesn't exist.



回答2:

This question was asked anout a year ago for IDEA 12, and at that time the Gradle support was still... let's say "in progress". In the meantime IDEA 13 is out, and the Gradle support plugin has improved dramatically. See this (short) video for the current capabilities: https://m.youtube.com/watch?v=3Euo6xzCwY4 It isn't a stupid menu walkthrough, it is a concrete example.