How to use Gradle Wrapper

摘要: In this tutorial, we will show you how to create Gradle wrapper for your project and how to use it.

In this tutorial, we will show you how to create Gradle wrapper for your project and how to use it.

What is Gradle wrapper?
The Gradle wrapper allows you to run a Gradle task without requiring that Gradle is installed on your system.

1. Create a Gradle Wrapper

1.1 Declares a wrapper task.

build.gradle
task wrapper(type: Wrapper) {
    gradleVersion = '2.10' //we want gradle 2.10 to run this project

1.2 Run the wrapper task with gradle wrapper

$ gradle wrapper
:wrapper
BUILD SUCCESSFUL

1.3 The following files will be created, remember to add these files and folders to your version control system (e.g GitHub or Bitbucket).

|-gradle
  |--- wrapper
      |--- gradle-wrapper.jar
      |--- gradle-wrapper.properties
|-gradlew
|-gradlew.bat 

Review the gradlew file, a unix shell script to run the Gradle task.

2. How to use Gradle Wrapper?

2.1 Assume your Gradle project along with the Gradle wrapper files are added to GitHub, and someone wants to clone your project and try to run it without installing Gradle on their system.

2.2 They can download the project and run it with gradlew, read comments for self-explanatory :

$ git clone https://github.com/mkyong/spring4-mvc-gradle-annotation-hello-world.git
$ cd spring4-mvc-gradle-annotation-hello-world
# wait, build? we don't have Gradle install yet? No problem, gradlew will handle it.
$ ./gradlew build  
# first time, download the gradle 2.10..
# download project dependencies
# run the gradle build task
# ...wow, we run a Gradle task without installing Gradle!
# try run jettyRun task
$ ./gradlew jettyRun
16:16:21 INFO  Jetty 9.2.10.v20150310 started and listening on port 8080
16:16:21 INFO  spring4 runs at:
16:16:21 INFO    http://localhost:8080/spring4
Press any key to stop the server.
$ ./gradlew task

Done.

References

  1. The Gradle Wrapper
  2. Building Java Projects with Gradle

上一篇: Jenkins Could not find GradleWrapperMain
下一篇: Gradle JaCoCo Incompatible version 1006
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号