Gradle Tutorial Description User Guide Chapter 7th Quick Build Java Engineering

Source: Internet
Author: User

Website address: http://www.gradle.org/docs/2.1/userguide/tutorial_java_projects.html


Using the Java pluginA basic Java Project with a basic Java engineeringusing the Java plugin in Build.gradle:Apply plugin: ' java '
Building The project construction projectThe Gradle/samples/java/quickstart sample project is used here. The shell enters the directory. > Gradle BuildThe tasks that the command runs on are (you can use Gradle TaskName to run one of the following tasks separately):
: Compilejava
:p rocessresources
: Classes
: Jar
: Assemble
: Compiletestjava
:p rocesstestresources
: testclasses
: Test
: Check
: Build

Prompt up-to-date indicates that the file is not updated and is up to date
after any successful execution, the build directory is generated under the current directory, and some of the directories generated under the build directory are: libs/ JAR file in the directorySrc/main/java/source Code
Src/test/java/test Source Code
Src/main/resources/will is include in the JAR file
Src/test/resources/will is include in the classpath used to run the tests

Some other useful tasks:
Clean clear the Build directory
Deletes the build directory, removing all built files. < Gradle Clean
Assemble compiling jar package : Compilejava
:p rocessresources
: Classes
: Jar
: Assemble
These five tasks are called. Compile, process resources, generate bytecode, generate jar packages < gradle assemble

External Dependencies External dependenciesTypically, a project references some external jar packages. Then you need to tell Gradle where to find them. in Gradle, such as a jar file, is located in a storage warehouse (repository).
Storage warehouses can be relied upon or released to make it independent (such as jar packages, Javadoc documents). This example uses the MAVEN repository.
Build.gradle:repositories {
Mavencentral ()
}

In this example, you need to add a. Java source compile-time dependency: commons-collections
and a test source when compiling the dependency: JUnit Build.gradle:
dependencies {
Compile group: ' Commons-collections ', Name: ' Commons-collections ', Version: ' 3.2 '
Testcompile group: ' JUnit ', Name: ' JUnit ', version: ' 4.+ '
}

Customizing the Project customization ProjectThe Java plugin adds a number of features to your project. These properties usually have default values. If they don't fit, it's easy to change these values. example, we will specify the version number for our Java project and the compilation level of our source code. In Jar-manifest, we also added some properties.
Build.gradle:
//java Compile version
Sourcecompatibility = 1.5
Project version
Version = ' 1.0 '
Jar {
Manifest {
Attributes ' Implementation-title ': ' Gradle Quickstart ',
' Implementation-version ': Version
}
}

Add a test system property Build.gradle:
Test {
Systemproperties ' property ': ' Value '
}

publishing the jar file releases the jar packagetypically a jar package needs to specify a location. is to tell gradle this position. Examples are packaged in a local directory. can also be published to a remote location or multiple locations Build.gradle:
uploadarchives {
repositories {
Flatdir {
Dirs ' repos '//publish to flat Dir:repos
}
}
}

Creating An Eclipse project creates an eclipse projectto create an eclipse-specific descriptor file, such as a. project file, you need to add another plugin to your build file:Build.gradle:
Apply plugin: ' Eclipse '
> Gradle Eclipse
Ls-al found out. Project
Similarly, discovering Gradle Java can also be performed:
: Compilejava Up-to-date
:p rocessresources Up-to-date
: Classes Up-to-date
: Javadoc
The result is that the Javadoc document is compiled and generated

Summary
Apply plugin: ' java ' Apply plugin: ' eclipse ' sourcecompatibility = 1.5version = ' 1.0 ' jar {    manifest {        attributes ' I Mplementation-title ': ' Gradle Quickstart ',                   ' implementation-version ': Version    }}repositories {    Mavencentral ()}dependencies {    compile group: ' Commons-collections ', Name: ' Commons-collections ', Version: ' 3.2 '    testcompile group: ' JUnit ', Name: ' JUnit ', version: ' 4.+ '}test {    systemproperties ' property ': ' Value '} uploadarchives {    repositories {       Flatdir {           dirs ' repos '}}    }






Gradle Tutorial Description User Guide Chapter 7th Quick Build Java Engineering

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.