官术网_书友最值得收藏!

Gradle

Gradle is a project automation tool that borrows a lot of concepts from Maven. It differs from Maven in using a Groovy-based declarative syntax instead of XML.

Note

Read more about Gradle at https://gradle.org. And, head over to http://www.groovy-lang.org for an introduction to Groovy.

Gradle has become a popular alternative to Maven for its flexibility and neater declarative syntax, while still offering powerful dependency management. We will take a quick look at dependency management in the next section.

Dependency management in Gradle

Gradle offers dependency resolution. It can be set up to use Maven's Central Repository. Let's consider a sample Gradle build (in a file called build.gradle):

apply plugin: 'java'

repositories {
    mavenCentral()
}

We instructed Gradle that we want to build a Java project and that the dependencies should be fetched from Maven's Central Repository. Now, we can simply declare the dependencies we require as follows:

dependencies {
  runtime group: 'org.hibernate', name: 'hibernate-core', version: '4.1.9.Final'
  testCompile group: 'junit', name: 'junit', version: '4.+'
}

The following Gradle build file declares two dependencies:

  • Hibernate: This is a runtime dependency that will be used during the project compilation and will be packaged with the application
  • JUnit: This dependency is added to the classpath that is used while running the tests. This type of dependency does not get included in the final application

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Tip

It is possible to use a remote Maven repository by adding the following to the build file:

repositories {
    maven {
        url "http://repo.mycompany.com"
    }
}

Maven and Gradle both offer excellent support for building our sample RESTful service, and the full build scripts can be downloaded along with all the source code of this book. Now, let's turn our attention to the structure of our property management system.

主站蜘蛛池模板: 永嘉县| 开阳县| 高州市| 阜城县| 卢氏县| 福贡县| 汾阳市| 突泉县| 灵宝市| 太原市| 新源县| 鄂州市| 万盛区| 天镇县| 井冈山市| 保康县| 青岛市| 凤台县| 平山县| 彭阳县| 巩留县| 湄潭县| 余干县| 宝鸡市| 贵定县| 景宁| 普安县| 永和县| 全椒县| 任丘市| 洛隆县| 乌鲁木齐县| 贺州市| 绥化市| 奎屯市| 垫江县| 缙云县| 甘谷县| 芜湖市| 曲阳县| 察雅县|