Eclipse Gradle配置

來源:互聯網
上載者:User

標籤:

一、Gradle簡介

Gradle 是以 Groovy 語言為基礎,面向Java應用為主。基於DSL(領特定領域語言)文法的自動化構建工具。

 

二、配置步驟如下

1、資源下載:

Grandle官網下載Gradle,地址:http://www.gradle.org/downloads

提示:如果只是運行可以只下載bin,為了擴充開發還是下載all。

 

2、下載完畢後,解壓zip至安裝目錄即可,例如:D:\Program Files

 

3、設定環境變數,需要設定如下2個環境變數

1、添加GRADLE_HOME指向gradle的安裝目錄的根目錄

GRADLE_HOME=D:\Program Files\gradle-2.0

2、Path變數添加gradle的bin目錄

D:\Program Files\gradle-2.0\bin

 

4、以上步驟設定完畢,開啟cmd,運行gradle -v看到gradle的版本資訊,配置完成。

 

5.開啟Eclipse,Help-->Install new software,輸入http://dist.springsource.com/release/TOOLS/gradle

如果提示找不到地址,估計是被牆掉了,需要FQ。如果找得到地址,選擇安裝項,然後一直下一步,直到安裝完畢,重啟Eclipse即可。

 

6.建立一個web項目,在根目錄下建立一個build.gradle檔案

build.gradle檔案內容如下: import org.gradle.plugins.ide.eclipse.model.Facet

apply plugin: ‘maven‘
apply plugin: ‘java‘
apply plugin: ‘war‘
apply plugin: ‘eclipse-wtp‘


sourceCompatibility = 1.8   // 設定 JDK 版本
webAppDirName = ‘WebContent‘    // 設定 WebApp 根目錄
sourceSets.main.java.srcDir ‘src‘   // 設定 Java 源碼所在目錄


// 設定 maven 庫地址
repositories { 
    mavenCentral() // 中央庫
    maven { url ‘http://localhost:8081/nexus/content/groups/public‘ } // 自訂庫地址
}


// 設定依賴
dependencies {
    providedCompile ‘javax.servlet:servlet-api:2.5‘ // 編譯期
    providedRuntime ‘javax.servlet:jstl:1.2‘    // 運行時
}


// 設定 Project Facets
eclipse {
    wtp {
        facet {
            facet name: ‘jst.web‘, type: Facet.FacetType.fixed
            facet name: ‘wst.jsdt.web‘, type: Facet.FacetType.fixed
            facet name: ‘jst.java‘, type: Facet.FacetType.fixed
            facet name: ‘jst.web‘, version: ‘2.5‘
            facet name: ‘jst.java‘, version: ‘1.8‘
            facet name: ‘wst.jsdt.web‘, version: ‘1.0‘
        }
    }
}

提示:項目有個G,正常情況下是沒有的,需要右鍵項目 "Configure->Convert to Gradle Project..",稍等下就OK了,就能像我有這個表徵圖G,

添加依賴包:需要右鍵項目"Gradle->Refresh All","Gradle->Dependency->Management".

 

8、可能報錯

Unable to start the daemon process.This problem might be caused by incorrect configuration of the daemon.For example, an unrecognized jvm option is used.Please refer to the user guide chapter on the daemon at http://gradle.org/docs/2.2.1/userguide/gradle_daemon.htmlPlease read the following process output to find out more:-----------------------Error occurred during initialization of VMCould not reserve enough space for object heapError: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.Could not fetch model of type ‘HierarchicalEclipseProject‘ using Gradle distribution ‘https://services.gradle.org/distributions/gradle-2.2.1-bin.zip‘.
解決方案
1、定位到目錄 C:\Users\<username>\.gradle 2、建立檔案gradle.properties    內容:org.gradle.jvmargs=-Xmx512m 3、重啟你的Android Studio項目,即可。

 

9、設定gradle下jar包的儲存地址, "window->preferences->gradle",如下:

Eclipse Gradle配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.