1. 程式人生 > >如何在IDEA裏正確導入從Github上下載的Gradle項目

如何在IDEA裏正確導入從Github上下載的Gradle項目

3.4 ktr mod fig ons div stack exc git

一、gradle安裝

1、 安裝jdk

  1.1 需要安裝jdk1.5以上才能運行gradle。

  1.2 驗證jdk是否安裝成功 java –version。

  1.3 設置JAVA_HOME環境變量。

2、 下載gradle

  地址:http://services.gradle.org/distributions/

技術分享圖片

技術分享圖片

技術分享圖片

3、 解壓gradle-3.5-bin.zip。

技術分享圖片

技術分享圖片

4、 設置GRADLE_HOME環境變量。

技術分享圖片

技術分享圖片

技術分享圖片

%GRADLE_HOME%\bin;

5、 驗證gradle 是否安裝成功 gradle –v 。

技術分享圖片

技術分享圖片
Microsoft Windows [版本 6.1.7601]
版權所有 (c) 2009 Microsoft Corporation。保留所有權利。

C:\Users\Administrator>gradle -version

------------------------------------------------------------
Gradle 3.5
------------------------------------------------------------

Build time:   2017-04-10 13:37:25 UTC
Revision:     b762622a185d59ce0cfc9cbc6ab5dd22469e18a6

Groovy:       2.4.10
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_66 (Oracle Corporation 25.66-b18)
OS:           Windows 7 6.1 amd64

C:\Users\Administrator>
技術分享圖片

二、從Github裏下載自己想要的項目源碼

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

方法一、

  1. 選擇菜單欄的File->Open

技術分享圖片

  2、在打開的窗口選擇對應Gradle項目的build.gradle文件,然後點擊OK

技術分享圖片

3、在Open Project窗口中,點擊Open as Project

技術分享圖片

4、在Import from Gradle窗口,配置你的Gradle項目,然後點擊ok

技術分享圖片

5、在Open Project窗口,點擊Open Existing Project按鈕。

  省略

6、最後,在New Project窗口根據自己需要選擇This WindowNew Window即可。

技術分享圖片

  成功!

方式二、用gradle構建產生IDEA工程文件

1、 進入cmd,切換到Gradle項目源碼根目錄

技術分享圖片

2、 執行命令:gradle idea

技術分享圖片

技術分享圖片
Microsoft Windows [版本 10.0.16299.125]
(c) 2017 Microsoft Corporation。保留所有權利。

C:\Users\lenovo>cd /d D:

D:\>cd D:\Code\IntelliJIDEAUltimateCode\paper\Hystrix-master

D:\Code\IntelliJIDEAUltimateCode\paper\Hystrix-master>gradle idea
技術分享圖片

  也許你會遇到這個問題:

技術分享圖片

技術分享圖片
> Configure project :
Git repository not found at D:\Code\IntelliJIDEAUltimateCode\paper\Hystrix-master -- nebula-release tasks 
will not be available. Use the git.root Gradle property to specify a different directory. FAILURE: Build failed with an exception. * Where: Build file ‘D:\Hystrix-master\build.gradle‘ line: 11 * What went wrong: An exception occurred applying plugin request [id: ‘nebula.netflixoss‘, version: ‘3.4.0‘] > Failed to apply plugin [id ‘nebula.netflixoss‘] > Cannot set property ‘defaultVersionStrategy‘ on null object * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. * Get more help at https://help.gradle.org BUILD FAILED in 1s D:\Code\IntelliJIDEAUltimateCode\paper\Hystrix-master>
技術分享圖片

 見Git學習系列之Windows上安裝Git之後的一些配置(圖文詳解)

解決辦法:

  編輯build.gradle文件,默認是

技術分享圖片

添加如下內容即可。

repositories {
        jcenter()
        maven {
            url ‘https://maven.google.com‘
        }
    }

技術分享圖片

3、 導入flume項目

3.1 選擇idea import project

技術分享圖片

3.2 選擇Gradle項目源碼位置

技術分享圖片

3.3 選擇外部model Gradle

技術分享圖片

3.4 選擇gradle home

技術分享圖片

技術分享圖片

如何在IDEA裏正確導入從Github上下載的Gradle項目