【问题标题】:How to setup a Java Gradle plugin project in IntelliJ?如何在 IntelliJ 中设置 Java Gradle 插件项目?
【发布时间】:2017-05-26 00:17:38
【问题描述】:

我在为 IntelliJ 设置 Java Gradle 插件项目时遇到问题。

具体来说,我无法让 Java 导入所需的 gradle 库。

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

【问题讨论】:

    标签: java intellij-idea gradle gradle-plugin


    【解决方案1】:

    我找到了 Groovy 的答案并将其移植到 Java。

    确保您已下载 gradle,并将 gradle bin 目录添加到您的路径。

    为您的项目创建一个新目录。打开命令提示符,然后运行以下命令:

    gradle init --type java-library
    

    然后编辑生成的 build.gradle 文件并添加以下依赖项:

    compile gradleApi()
    

    还有以下:

    apply plugin: 'idea'
    

    这应该会生成一个如下所示的 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'
    }
    

    然后回到命令提示符,运行:

    gradlew idea
    

    并在 IntelliJ 中打开生成的项目

    Groovy 来源:How to setup a Gradle plugin project in IntelliJ?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多