Create a Gradle project with IntelliJ idea Easy start

Source: Internet
Author: User

Original link: http://www.cnblogs.com/guogangj/p/5465740.html

Gradle, like Maven, is one of the most used build tools in Java, and before Maven, solving the problem with the jar-package reference was maddening, with Maven having a better day, and now with the Gradle,maven features it has, and looks more beautiful, Let's use them.

Once the IntelliJ idea is installed, Gradle is installed by default, and now we just need to create the project directly:

Of course, Java was chosen, Next:

Groupid,artifactid and version, I look like maven? In fact, we continue to use Maven's warehouses in the back. Next:

Use Auto-import and create directories for empty content roots automatically these two options tick, Next:

Fill in the project name, location, Ok,finish. Let's take a look at the directory structure of the project:

    • Support files for. Gradle,gradle, no Tube
    • . Idea,intellij the relevant documents of idea, do not care
    • Build, building the build, and storing the class and jar packages generated in the project build
    • Gradle, a gradle packaging procedures, seemingly directly with gradle not too good, we have to pack a layer, this actually we do not have to tube
    • SRC, where we write the code, needless to say.
    • Build.gradle,gradle's build configuration, that's what we're interested in, equivalent to Maven's Pom.xml
    • Project file for Gradlelearn.iml,intellij idea
    • Gradlew, a Gradle wrapper run script, for *nix
    • Gradlew.bat, a Gradle wrapper run script, for Windows

I used the applet provided in the previous article as an example (Java async httpclient) to see how to introduce Httpasyncclient and open our new "Pom.xml" (build.gradle):

Group ' Com.gornix ' version ' 1.0-snapshot ' Apply plugin: ' java ' sourcecompatibility = 1.8repositories {
Mavenlocal () mavencentral ()}

Tasks.withtype (javacompile) {
options.encoding = "UTF-8"
}
dependencies {    Compile group: ' Org.apache.httpcomponents ', Name: ' Httpasyncclient ', version: ' 4.1.1 '    Testcompile group: ' JUnit ', Name: ' JUnit ', Version: ' 4.11 '}

The red font Part I modified, to see if Build.gradle is more beautiful than pom.xml, quite concise, right.

The mavencentral () sentence means that using Maven's container to obtain the dependency, and with mavenlocal () This sentence, Gradle will try to get the jar package from the local MAVEN cache first, it will be faster, The following dependencies is a variety of dependency packages, compile represents compile-time dependencies, and Testcompile represents the compilation dependency when performing unit tests. Task.withtype () This paragraph represents the use of UTF-8 encoding, in order to avoid the problem of compilation, we all use UTF-8 encoding can, well, is the entire text file!

OK, click Refresh in the Gradle tool window:

When you expand the external libraries view in the Project window, you should be able to see that the relevant package is referenced.

The other seems to be no different, this article is just a "simple primer" article, so not much content, we still do not see Gradle than maven strong to go, just the configuration file nice point, and so later, if there is time, I will tidy up.

Create a Gradle project with IntelliJ idea Easy start

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.