简体   繁体   English

如何在IntelliJ中设置Java Gradle插件项目?

[英]How to setup a Java Gradle plugin project in IntelliJ?

I'm having issues setting up a Java Gradle Plugin project for IntelliJ. 我在为IntelliJ设置Java Gradle插件项目时遇到问题。

Specifically, I can't get the Java to import the required gradle library. 具体来说,我无法让Java导入所需的gradle库。

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

I found the answer for Groovy and ported it over for Java. 我找到了Groovy的答案并将其移植到Java。

Insure you have gradle downloaded, and the gradle bin directory added to your path. 确保已下载gradle,并将gradle bin目录添加到了路径中。

Create a new directory for your project to exist in. Open up command prompt, and run the following command: 为项目创建一个新目录。打开命令提示符,然后运行以下命令:

gradle init --type java-library

Then edit the generated build.gradle file and add the following the the dependencies: 然后编辑生成的build.gradle文件并添加以下依赖项:

compile gradleApi()

Also and the following: 以及以下内容:

apply plugin: 'idea'

This should result in a build.gradle that looks like: 这将导致一个build.gradle看起来像:

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'idea'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    compile gradleApi()

    // The production code uses Guava
    compile 'com.google.guava:guava:20.0'

    // Use JUnit test framework
    testCompile 'junit:junit:4.12'
}

Then back in command prompt, run: 然后返回命令提示符,运行:

gradlew idea

And open the generated project in IntelliJ 并在IntelliJ中打开生成的项目

Groovy Source: How to setup a Gradle plugin project in IntelliJ? Groovy来源: 如何在IntelliJ中设置Gradle插件项目?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM