Eclipse Install Gradle Plugin

Source: Internet
Author: User
Tags final socket zip

Http://www.cnblogs.com/simoncook/archive/2013/02/28/2937939.html

First, Introduction

1. What is Gradle Gradle official description is: Ability to automatically build, test, deploy, package, generate static pages, generate documents, and so on. Gradle integrates Ant's better-than-configured features to rely on management's power, flexibility, and MAVEN conventions to form a more efficient way to build. Gradle is based on groovy's domain definition language, full of innovation. Gradle has become a compilation system choice for many open source projects.

2. Gradle's features are described in detail in its documentation.

A. Build through declarations and build through conventions.

B. To describe language dependencies based on programming.

C. Structuring the description of the build. (Make your build code more elegant, clearer, and easier to reuse).

D. Deep API (provides many hooks that allow you to monitor and customize configurations at any point in the build. )。

E. Gradle scales. F. Multi-engineering construction.

G. Manage your dependencies in a variety of ways (you can connect directly with Maven and Ivy warehouses) ...

Second, Eclipse installs Gradle plug-in (highly recommended full Fan/qiang)

1. Access Http://dist.springsource.com/release/TOOLS/composite/e3.7/bookmarks.xml (Fan/qiang may be needed.) And 3.7 In this URL is a variable, determined by your version of Eclipse. )。 Save the XML file to local.

2. Then follow the diagram. Step 5 is Http://dist.springsource.com/release/TOOLS/gradle

And then all the way next.

3. After installing the configuration after installation, you can drink Maven's plug-in, you can specify where Gradle installed, or use the plug-in with the Gradle warpper. See what you need. I use the default self-bring. (Maven is a recommended point to install)

Iii. gradle Build Script Foundation

1. Basic installation A. Need to jdk1.5+. The specific step is to download the ZIP package, decompression can be used. If necessary, decide whether to set the GRADLE_HOME environment variable and whether the Gradle_home/bin directory joins the system path. B. JVM parameter configuration. For gradle, configuring JVM parameters can be configured through gradle_opts and java_opts, such as HTTP proxies. You can also set it at the beginning of the Gradle script.

2. Eclipse's Gradle plugin using the eclipse's Gradle plugin to create the Gradle project will fail if it is not networked. The error message is as follows: Java.net.UnknownHostException:services.gradle.org at Java.net.PlainSocketImpl.connect (Unknown Source) at Java.net.SocksSocketImpl.connect (Unknown source) at Java.net.Socket.connect (Unknown source) at Java.net.Socket.connect (Unknown Source) at Sun.net.NetworkClient.doConnect (Unknown Sourc

3. Gradle Script Basics

A. Everything in Gradle sits on top of both basic concepts:projects and tasks. Every Gradle build is made up by one or more projects. There are two important concepts in Gradle, project and task. Each gradle build script has multiple project components. A project represents some parts of the software you want to build. What you want to build depends on what's outside. A project might represent a jar lib, or a web app. A project may also represent a zip package that is assembled by multiple jar packages built from multiple projects. A project does not necessarily mean building or doing something, such as publishing your app to a presentation or production environment.

B. Each project is also composed of multiple tasks. A task represents a working fragment of some atomic build execution. such as compiling classes, creating jars, generating javadoc, releasing some compressed packages to the warehouse.

Here's a look at groovy's syntax. See another article in this blog : Groovy Concise Learning

C. Hello World Create a Build.gradle and write the following code:

Task Hello {dolast {println ' Hello world! '}}

The-B option of Gradle indicates that the compilation script file is specified. The above script explains a few, defines a hello task, and executes it. This task is equivalent to Ant's target, but the Gradle task has more powerful features.

D. Faster task definition.

Task Hello << {println ' Hello world! '}

E. String method Use

Task Upper << {String somestring = ' my_name ' println "Original:" + somestring println "upper case:" + somestring. toUpperCase ()}

F. Number of iterations task count << {4.times {print "$it"}}

G. Tasks dependent task Hello << {println ' Hello world! '} Task Intro (Dependson:hello) << {println "I ' m Gradle"}

H. Dynamic task 4.times {counter-a task "Task$counter" << {println "I ' m task number $counter"}}

Not finished, to write

I. Working with tasks that already exist

==========================

http://yidwo.iteye.com/blog/1848990

1. Gradle Installation:
Download the latest version from the official website www.gradle.org and add the Gradle_home/bin directory to the System environment variable path after decompression. Test whether the configuration was successfully run at the command line: GRADLE-V will print out information such as the Gradle version number.

2. Gradle Basic use:
After creating a new project, create a Build.gradle file under the project folder and add the content:
Apply plugin: ' Eclipse '.
Then run Gradle Eclipse at the terminal to build the Eclipse IDE's development environment.

Gradle Default value: Gradle Some directories are present with default values, and the proposed configuration of the project inherits the Maven style, such as:
Java Source directory: Src/main/java
Java Test Code Catalog: Src/test/java
Resource Files directory: src/main/resources
Resource directory for testing: src/test/resources
Directory for Web project: Src/main/webapp can be changed by Webappdirname variable ex:webappdirname= "WebApp"

Here is one of my Web project's Build.gradle file, let's preview it, then step into a simple introduction:
Java code apply plugin:  ' maven '        apply plugin:  ' war '         apply plugin:  ' ECLIPSE-WTP '        apply  plugin:  ' jetty '           webAppDirName =  ' WebApp '           repositories {            mavencentral ()        }            dependencies {           compile  (                 "Javax.servlet: Javax.servlet-api:3.1-b07 ",                  "org.slf4j:slf4j-log4j12:1.7.5",                  "Org.slf4j:slf4j-jdk14:1.7.5 ",                " mysql:mysql-connector-java:5.1.24 "           )        }           task copyhbm (type: copy) {            from  ' Src/main/java/com/base/model '             into  ' Build/classes/main/com/base/model '             exclude  ' **/*.java '         }  

Apply plugin: ' maven '
	Apply plugin: ' War '
	Apply plugin: ' ECLIPSE-WTP '
	apply plugin: ' Jetty '

	Webappdirname = ' WebApp '

	repositories {
	    mavencentral ()
	}

	dependencies {
	    compile (
	    	" Javax.servlet:javax.servlet-api:3.1-b07 ",
	    	" org.slf4j:slf4j-log4j12:1.7.5 ",
	    	" org.slf4j:slf4j-jdk14 : 1.7.5 ",
	    	" mysql:mysql-connector-java:5.1.24 "
	    )
	}

	task Copyhbm (type:copy) {from
		' src/ Main/java/com/base/model ' into
		' Build/classes/main/com/base/model '
		exclude ' **/*.java '
	}



Build.gradle file Common Task resolution:
Apply plugin: ' maven ':Use MAVEN as a trust management for jar packages to download the trust packs required for projects through the Mave warehouse
Apply plugin: ' War ':Specifies a Web project that generates a war package for a project when it is compiled (executed at the project prompt: Gradle build).
Apply plugin: ' java ':Specifies that the project is a Java project, and the project is compiled (executed at Project prompt: Gradle build) When the project's jar package is built.
Apply plugin: ' ECLIPSE-WTP ':The plug-in builds the Web project's development environment, generating the required. project,.classpath files. Because my web development uses the ECLIPSE-J2EE version, it is designated as a WTP environment.
Apply plugin: ' Eclipse ':Build the Eclipse development environment for your Java project. Generate the required. project,.classpath files.
Apply plugin: ' Jetty ':Add support for jetty, and execute the command Gradle Jettyrun to run the Web project directly after the code is modified.
repositories:Specifies the warehouse to use.
dependencies:Project dependency definitions, compile for compile-level dependencies, and testcompile for test-level dependencies.
Compile:There are several ways to configure the dependency configuration of a jar package, which I'm using in a more abbreviated way, with one of the following:
Java code compile Group: ' Org.hibernate ', Name: ' Hibernate-core ', version: ' 3.6.7.Final ' testcompile group: ' JUnit ', name: ' JUnit ', version: ' 4.+ '

         Compile group: ' Org.hibernate ', Name: ' Hibernate-core ', version: ' 3.6.7.Final '
         testcompile group: ' JUnit ', Name: ' JUnit ', version: ' 4.+ '


    task COPYHBM (type:copy): is a custom task to copy Hibernate mapping files to the correct directory. Gradle only the Java file name is packaged under the default source package, and the XML file is ignored. You can perform task-defined actions Gradle COPYHBM at the project prompt.
   
Gradle common commands:
     
         gradle Eclipse: Build the development environment, download the defined jar package
        gradle Build: Compile the project, Generate the Build folder and generate the appropriate jar or war package.
        gradle Clean: In contrast to build, delete the build folder.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.