Best way to add Gradle support to IntelliJ Project

前端 未结 7 1108
梦如初夏
梦如初夏 2020-11-28 18:27

I have looked around quite a bit and haven\'t found the best solution to convert an existing IntelliJ project to Gradle. I work in a team environment and we currently share

相关标签:
7条回答
  • 2020-11-28 19:02

    Add:

    build.gradle 
    

    in your root project folder, and use plugin for example:

    apply plugin: 'idea'
    //and standard one
    apply plugin: 'java'
    

    and with this fire from command line:

    gradle cleanIdea 
    

    and after that:

    gradle idea
    

    After that everything should work

    0 讨论(0)
  • 2020-11-28 19:03

    Another way, simpler.

    Add your

    build.gradle
    

    file to the root of your project. Close the project. Manually remove *.iml file. Then choose "Import Project...", navigate to your project directory, select the build.gradle file and click OK.

    0 讨论(0)
  • 2020-11-28 19:06
    1. Add build.gradle in your project's root directory.

    2. Then just File -> Invalidate Caches / Restart

    Here is a basic build.gradle for Java projects:

    plugins {
        id 'java'
    }
    
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
    version = '1.2.1'
    
    0 讨论(0)
  • 2020-11-28 19:09

    In IntelliJ 2017.2.4 I just closed the project and reopened it and I got a dialog asking me if I wanted to link with build.gradle which opened up the import dialog for Gradle projects.

    No need to delete any files or add the idea plugin to build.gradle.

    0 讨论(0)
  • 2020-11-28 19:16

    Just as a future reference, if you already have a Maven project all you need to do is doing a gradle init in your project directory which will generates build.gradle and other dependencies, then do a gradle build in the same directory.

    0 讨论(0)
  • I'm using Version 12 of IntelliJ.

    I solved a similar problem by creating an entirely new project and "Checking out from Version Control" Merging the two projects later was fairly easy.

    0 讨论(0)
提交回复
热议问题