zoukankan      html  css  js  c++  java
  • Eclipse Gradle配置

    一、Gradle简介

    Gradle 是以 Groovy 语言为基础,面向Java应用为主。基于DSL(领域特定语言)语法的自动化构建工具。

    二、配置步骤如下

    1、资源下载:

    Grandle官网下载Gradle,地址:http://www.gradle.org/downloads

    image

    提示:如果只是运行可以只下载bin,为了扩展开发还是下载all。

    2、下载完毕后,解压zip至安装目录即可,例如:D:Program Files

     

    3、设置环境变量,需要设置如下2个环境变量

    1、添加GRADLE_HOME指向gradle的安装目录的根目录

    GRADLE_HOME=D:Program Filesgradle-2.0

    2、Path变量添加gradle的bin目录

    D:Program Filesgradle-2.0in

     

    4、以上步骤设置完毕,打开cmd,运行gradle -v看到gradle的版本信息,配置完成。

    image

     

    5.打开Eclipse,Help-->Install new software,输入http://dist.springsource.com/release/TOOLS/gradle

    如果提示找不到地址,估计是被墙掉了,需要翻墙。如果找得到地址,选择安装项,然后一直下一步,直到安装完毕,重启Eclipse即可。

    image

     

    6.创建一个web项目,在根目录下创建一个build.gradle文件

    image

    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.html
    Please read the following process output to find out more:
    -----------------------
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    Error: 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项目,即可。

    image

    9、设置gradle下jar包的保存地址, "window->preferences->gradle",如下:

    image

  • 相关阅读:
    git学习记录——基础概念和文件的基本操作
    java 之 Properties 类
    java 之 Map类
    java 之 迭代器
    java 之 Collection类
    java 之日期时间操作
    java 之String类
    如何把ASP.NET MVC项目部署到本地IIS上
    [工具]Visual Studio
    [MVC][Shopping]Copy Will's Code
  • 原文地址:https://www.cnblogs.com/274914765qq/p/4401525.html
Copyright © 2011-2022 走看看