{"id":81736,"date":"2020-09-24T16:03:23","date_gmt":"2020-09-24T16:03:23","guid":{"rendered":"https:\/\/www.baeldung.com\/?p=87529"},"modified":"2020-09-24T16:03:23","modified_gmt":"2020-09-24T16:03:23","slug":"guide-to-the-gradle-wrapper","status":"publish","type":"post","link":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/2020\/09\/24\/guide-to-the-gradle-wrapper\/","title":{"rendered":"Guide to the Gradle Wrapper"},"content":{"rendered":"<p class=\"syndicated-attribution\"><meta name= \\\"keywords \\\" content= \\\"\u96fb\u5b50\u8a08\u7b97\u6a5f, \u6559\u80b2, IT \u96fb\u8166\u73ed,\u96fb\u8166\u88dc\u7fd2\uff0c \u96fb\u8166\u73ed\uff0c \u5bb6\u6559\uff0c \u79c1\u4eba\u8001\u5e2b\uff0c \u8cc7\u8a0a\u6280\u8853\uff0c \u7a0b\u5e8f\u8a2d\u8a08\uff0c \u96fb\u5b50\u8a08\u7b97\u6a5f\uff0c \u904a\u6232\uff0c \u860b\u679c\uff0c \u96fb\u5f71\uff0c \u8a08\u7b97\u6a5f\uff0c\u7de8\u78bc\uff0c Java\uff0c C\/C++\uff0c JavaScript\uff0c PHP\uff0c HTML\uff0c CSS\uff0c MySQL\uff0c mobile\uff0c Android\uff0c \u52d5\u6f2b\uff0c Python\uff0c teacher\uff0c \u88dc\u7fd2\uff0c \u96fb\u8166\u88dc\u7fd2 \u8cc7\u8a0a, \u7535\u5b50\u8ba1\u7b97\u673a, IT ,Game, apple, movie, Computer,student,Java,\u6559\u80b2, ,\u5b66\u751f, \u5b66\u4e60, learn, \u6559\u5b66,  Android, apple,anime, animation, \u4fe1\u606f\u6280\u672f, \u7a0b\u5e8f\u8bbe\u8ba1, \u79fb\u52a8\u7535\u8bdd, \u8cc7\u8a0a\u79d1\u6280,Game, Jeu, Juego,Call Of Duty ,\u4f7f\u547d\u53ec\u559a , \u6e38\u620f, \u7535\u5b50\u6e38\u620f,, \u591a\u4eba\u7535\u5b50\u6e38\u620f, \u7f51\u7edc\u6e38\u620f\uff0conline\uff0conline game, \u624b\u673a\u6e38\u620f, mobile \\\"><\/p>\n<h2 data-id=\"overview\">1. Overview<\/h2>\n<div class=\"bd-anchor\" id=\"overview\"><\/div>\n<p><a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/gradle\">Gradle<\/a> is commonly used by developers to manage their project&#8217;s build lifecycle. It&#8217;s the default choice of build tool for all new Android projects.<\/p>\n<p>In this tutorial, we&#8217;ll learn about Gradle Wrapper, an accompanying utility that makes it easier to distribute projects.<\/p>\n<h2 data-id=\"gradle-wrapper\">2. Gradle Wrapper<\/h2>\n<div class=\"bd-anchor\" id=\"gradle-wrapper\"><\/div>\n<p>To build a Gradle-based project, we need to have Gradle installed in our machine. However, if our installed version doesn&#8217;t match with the project&#8217;s version, we&#8217;ll probably face many incompatibility problems.<\/p>\n<p>Gradle Wrapper, also called <em>Wrapper <\/em>in short, solves this problem. <strong>It&#8217;s a script that runs Gradle tasks with a declared version<\/strong>. If the declared version is not installed, Wrapper installs the required one.<\/p>\n<p>The main benefits of Wrapper are that we can:<\/p>\n<ul>\n<li><strong>Build a project with Wrapper on any machine without the need to install Gradle first<\/strong><\/li>\n<li>Have a fixed Gradle version. This yields reusable and more robust builds on CI pipelines<\/li>\n<li>Upgrade to a new Gradle version easily by changing the Wrapper definition<\/li>\n<\/ul>\n<p>In the next sections, we&#8217;ll be running Gradle tasks that require <a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/gradle.org\/install\/\">Gradle to be installed locally<\/a>.<\/p>\n<h3 data-id=\"1-generating-wrapper-files\">2.1. Generating Wrapper Files<\/h3>\n<div class=\"bd-anchor\" id=\"1-generating-wrapper-files\"><\/div>\n<p>To use Wrapper, we need to generate some particular files. <strong>We&#8217;ll generate these files using the built-in Gradle task called <em>wrapper. <\/em><\/strong>Note that we need to generate these files only once.<\/p>\n<p>Now, let&#8217;s run the <em>wrapper<\/em> task in our project directory:<\/p>\n<pre><code class=\"language-java\">$ gradle wrapper\r\n<\/code><\/pre>\n<p>Let&#8217;s see the output of this command:<\/p>\n<p><a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/wp-content\/uploads\/2020\/09\/gradle-wrapper.png\"><img decoding=\"async\" loading=\"lazy\" width=\"282\" height=\"117\" class=\"alignnone size-full wp-image-87635\" src=\"https:\/\/www.baeldung.com\/wp-content\/uploads\/2020\/09\/gradle-wrapper.png\" alt=\"\" srcset=\"https:\/\/www.baeldung.com\/wp-content\/uploads\/2020\/09\/gradle-wrapper.png 282w, https:\/\/www.baeldung.com\/wp-content\/uploads\/2020\/09\/gradle-wrapper-100x41.png 100w\" sizes=\"(max-width: 282px) 100vw, 282px\" \/><\/a><\/p>\n<p>Let&#8217;s have a look at what these files are:<\/p>\n<ul>\n<li><em>gradle-wrapper.jar<\/em> contains code for downloading the Gradle distribution specified in the <em>gradle-wrapper.properties\u00a0<\/em>file<\/li>\n<li><em>gradle-wrapper.properties<\/em> contains Wrapper runtime properties \u2014 most importantly, the version of the Gradle distribution that is compatible with the current project<\/li>\n<li><em>gradlew<\/em> is the script that executes Gradle tasks with the Wrapper<\/li>\n<li><em>gradlew.bat<\/em> is the <em>gradlew<\/em> equivalent batch script for Windows machines<\/li>\n<\/ul>\n<p>By default, the <em>wrapper<\/em> task generates Wrapper files with the Gradle version currently installed on the machine. We can specify another version if needed:<\/p>\n<pre><code class=\"language-java\">$ gradle wrapper --gradle-version 6.3\r\n<\/code><\/pre>\n<p><strong>We recommended checking the Wrapper files into<\/strong> <strong>the source control system<\/strong> like GitHub. This way we ensure that other developers can run the project without the need to install Gradle.<\/p>\n<h3 data-id=\"2-running-gradle-commands-with-wrapper\">2.2. Running Gradle Commands with Wrapper<\/h3>\n<div class=\"bd-anchor\" id=\"2-running-gradle-commands-with-wrapper\"><\/div>\n<p><strong>We can run any Gradle task with the Wrapper by replacing <em>gradle<\/em> with <\/strong><em><strong>gradlew<\/strong>.<\/em><\/p>\n<p>To list the available tasks, we can use the <em>gradlew tasks<\/em> command:<\/p>\n<pre><code class=\"language-shell\">$ gradlew tasks<\/code><\/pre>\n<p>Let&#8217;s have a look at the output:<\/p>\n<pre><code class=\"language-shell\">Help tasks\r\n----------\r\nbuildEnvironment - Displays all buildscript dependencies declared in root project 'gradle-wrapper'.\r\ncomponents - Displays the components produced by root project 'gradle-wrapper'. [incubating]\r\ndependencies - Displays all dependencies declared in root project 'gradle-wrapper'.\r\ndependencyInsight - Displays the insight into a specific dependency in root project 'gradle-wrapper'.\r\ndependentComponents - Displays the dependent components of components in root project 'gradle-wrapper'. [incubating]\r\nhelp - Displays a help message.\r\nmodel - Displays the configuration model of root project 'gradle-wrapper'. [incubating]\r\noutgoingVariants - Displays the outgoing variants of root project 'gradle-wrapper'.\r\nprojects - Displays the sub-projects of root project 'gradle-wrapper'.\r\nproperties - Displays the properties of root project 'gradle-wrapper'.\r\ntasks - Displays the tasks runnable from root project 'gradle-wrapper'.<\/code><\/pre>\n<p>As we can see, the output is the same as we would get when running this task with the <em>gradle<\/em> command.<\/p>\n<h2 data-id=\"common-issues\">3. Common Issues<\/h2>\n<div class=\"bd-anchor\" id=\"common-issues\"><\/div>\n<p>Now, let&#8217;s look at some common issues that we may face when working with Wrapper.<\/p>\n<h3 data-id=\"1-global-gitignore-that-ignores-all-jar-files\">3.1. <strong>Global .gitignore That Ignores All Jar Files<\/strong><\/h3>\n<div class=\"bd-anchor\" id=\"1-global-gitignore-that-ignores-all-jar-files\"><\/div>\n<p>Some organizations do not allow developers to check jar files into their source control system. Typically, such projects have a rule in the global <em>.gitignore<\/em> file to ignore all jar files. Therefore, the <em>gradle-wrapper.jar<\/em> file is not checked into the git repository. For this reason, Wrapper tasks fail to run on other machines. In such cases, <strong>we need to add the <em>gradle-wrapper.jar<\/em> file to git forcefully<\/strong>:<\/p>\n<pre><code class=\"language-shell\">git add -f gradle\/wrapper\/gradle-wrapper.jar<\/code><\/pre>\n<p>Similarly, we may have a project-specific <em>.gitignore<\/em> file that ignores jar files. We can fix it either by relaxing the <em>.gitignore<\/em> rule or by adding the wrapper jar file forcefully, as shown above.<\/p>\n<h3 data-id=\"2-missing-wrapper-folder\"><strong>3.2. Missing Wrapper Folder<\/strong><\/h3>\n<div class=\"bd-anchor\" id=\"2-missing-wrapper-folder\"><\/div>\n<p>When checking in a Wrapper-based project, we may forget to include the <em>wrapper<\/em> folder that exists inside the <em>gradle<\/em> folder. But as we have seen above, the <em>wrapper<\/em> folder contains two critical files: <em>gradle-wrapper.jar <\/em>and <em>gradle-wrapper.properties.<\/em><\/p>\n<p>Without these files, we&#8217;ll get errors when running Gradle tasks with the Wrapper. Therefore, <strong>we must check the <em>wrapper<\/em> folder into the source control system<\/strong>.<\/p>\n<h3 data-id=\"3-removed-wrapper-files\"><strong>3.3. Removed Wrapper Files<\/strong><\/h3>\n<div class=\"bd-anchor\" id=\"3-removed-wrapper-files\"><\/div>\n<p><span style=\"font-weight: 400\">Gradle-based projects contain a <em>.gradle<\/em> folder that stores cache to speed up Gradle tasks. Sometimes, we need to clear the cache <\/span><span style=\"font-weight: 400\">in order to troubleshoot Gradle build issues. <\/span><span style=\"font-weight: 400\">Usually, we remove the entire <em>.gradle<\/em> folder. <\/span>But we may mistake the Wrapper <i>gradle<\/i> folder with the <i>.gradle<\/i><span style=\"font-weight: 400\"> folder and remove it, too. After that, we&#8217;ll definitely face problems when trying to run Gradle tasks with the Wrapper.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>We can solve this problem by pulling the latest changes from the source<\/strong>. Alternatively, we can regenerate the Wrapper files.<\/span><\/p>\n<h2 data-id=\"conclusion\">4. Conclusion<\/h2>\n<div class=\"bd-anchor\" id=\"conclusion\"><\/div>\n<p>In this tutorial, we learned about Gradle Wrapper and its basic usage. We also learned about some common problems we may face when working with Gradle Wrapper.<\/p>\n<p>As usual, we can check the project with generated Gradle Wrapper files <a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/github.com\/eugenp\/tutorials\/tree\/master\/gradle\/gradle-wrapper\">over on GitHub<\/a>.<\/p>\n<p>The post <a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/gradle-wrapper\/\" >Guide to the Gradle Wrapper<\/a> first appeared on <a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/\" >Baeldung<\/a>.<\/p>\n<p><Img align=\"left\" border=\"0\" height=\"1\" width=\"1\" alt=\"\" style=\"border:0;float:left;margin:0;padding:0;width:1px!important;height:1px!important;\" hspace=\"0\" src=\"https:\/\/feeds.feedblitz.com\/~\/i\/635924664\/0\/baeldung\"><\/p>\n<div style=\"clear:both;padding-top:0.2em;\"><a title=\"Like on Facebook\" href=\"https:\/\/feeds.feedblitz.com\/_\/28\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/fblike20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Share on Google+\" href=\"https:\/\/feeds.feedblitz.com\/_\/30\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/googleplus20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Pin it!\" href=\"https:\/\/feeds.feedblitz.com\/_\/29\/635924664\/baeldung,https%3A%2F%2Fwww.baeldung.com%2Fwp-content%2Fuploads%2F2020%2F09%2Fgradle-wrapper.png\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/pinterest20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Tweet This\" href=\"https:\/\/feeds.feedblitz.com\/_\/24\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/twitter20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Subscribe by email\" href=\"https:\/\/feeds.feedblitz.com\/_\/19\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/email20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Subscribe by RSS\" href=\"https:\/\/feeds.feedblitz.com\/_\/20\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/rss20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a rel=\"NOFOLLOW\" title=\"View Comments\" href=\"https:\/\/www.baeldung.com\/gradle-wrapper#respond\"><img decoding=\"async\" height=\"20\" style=\"border:0;margin:0;padding:0;\" src=\"https:\/\/assets.feedblitz.com\/i\/comments20.png\"><\/a>&#160;<a title=\"Follow Comments via RSS\" href=\"https:\/\/www.baeldung.com\/gradle-wrapper\/feed\/\"><img decoding=\"async\" height=\"20\" style=\"border:0;margin:0;padding:0;\" src=\"https:\/\/assets.feedblitz.com\/i\/commentsrss20.png\"><\/a>&#160;<\/div>\n\n<p class=\"syndicated-attribution\"><figure class= \\\"wp-block-image alignnone \\\"><img src= \\\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/05\/logo2-2.png\\\" alt=\\\"IT\u96fb\u8166\u88dc\u7fd2 java\u88dc\u7fd2 \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b, PHP\u88dc\u7fd2,CSS\u88dc\u7fd2,XML,Java\u88dc\u7fd2,MySQL\u88dc\u7fd2,graphic design\u88dc\u7fd2,\u4e2d\u5c0f\u5b78ICT\u88dc\u7fd2,\u4e00\u5c0d\u4e00\u79c1\u4eba\u88dc\u7fd2\u548cFreelance\u81ea\u7531\u5de5\u4f5c\u914d\u5c0d\u3002\\\"\/><figcaption>\u7acb\u523b\u8a3b\u518a\u53ca\u5831\u540d\u96fb\u8166\u88dc\u7fd2\u8ab2\u7a0b\u5427!<\/figcaption><\/figure>\r\n<\/br>Find A Teacher Form:\r\n<\/br>https:\/\/docs.google.com\/forms\/d\/1vREBnX5n262umf4wU5U2pyTwvk9O-JrAgblA-wH9GFQ\/viewform?edit_requested=true#responses\r\n<\/br><\/br>Email:\r\n<\/br>public1989two@gmail.com<br><br><br><br><br><br><br>\r\n<a href=www.itsec.hk style=color:#FFFFFF;>www.itsec.hk<\/a><br>\r\n<a href=\\\"www.itsec.vip\\\" style=color:#FFFFFF;>www.itsec.vip<\/a><br>\r\n<a href=\\\"www.itseceu.uk\\\" style=color:#FFFFFF;>www.itseceu.uk<\/a><br><\/p>","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>In this tutorial, we&#8217;ll learn about Gradle Wrapper, an accompanying utility that makes it easier to distribute projects.<\/p>\n<p>The post <a rel=\"NOFOLLOW noopener noreferrer\" href=\"https:\/\/feeds.feedblitz.com\/~\/635924664\/0\/baeldung~Guide-to-the-Gradle-Wrapper\/\" target=\"_blank\">Guide to the Gradle Wrapper<\/a> first appeared on <a rel=\"NOFOLLOW noopener noreferrer\" href=\"https:\/\/www.baeldung.com\/\" target=\"_blank\">Baeldung<\/a>.<\/p>\n<div><a title=\"Like on Facebook\" href=\"https:\/\/feeds.feedblitz.com\/_\/28\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/fblike20.png\"><\/a>&nbsp;<a title=\"Share on Google+\" href=\"https:\/\/feeds.feedblitz.com\/_\/30\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/googleplus20.png\"><\/a>&nbsp;<a title=\"Pin it!\" href=\"https:\/\/feeds.feedblitz.com\/_\/29\/635924664\/baeldung,https%3A%2F%2Fwww.baeldung.com%2Fwp-content%2Fuploads%2F2020%2F09%2Fgradle-wrapper.png\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/pinterest20.png\"><\/a>&nbsp;<a title=\"Tweet This\" href=\"https:\/\/feeds.feedblitz.com\/_\/24\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/twitter20.png\"><\/a>&nbsp;<a title=\"Subscribe by email\" href=\"https:\/\/feeds.feedblitz.com\/_\/19\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/email20.png\"><\/a>&nbsp;<a title=\"Subscribe by RSS\" href=\"https:\/\/feeds.feedblitz.com\/_\/20\/635924664\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/rss20.png\"><\/a>&nbsp;<a rel=\"NOFOLLOW\" title=\"View Comments\" href=\"https:\/\/www.baeldung.com\/gradle-wrapper#respond\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/comments20.png\"><\/a>&nbsp;<a title=\"Follow Comments via RSS\" href=\"https:\/\/www.baeldung.com\/gradle-wrapper\/feed\/\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/commentsrss20.png\"><\/a>&nbsp;<\/div>\n<\/div>","protected":false},"author":214,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Guide to the Gradle Wrapper - ITTeacherITFreelance.hk","description":"In this tutorial, we'll learn about Gradle Wrapper, an accompanying utility that makes it easier to distribute projects. The post Guide to the Gradle Wrapper fi"},"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/81736"}],"collection":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/214"}],"replies":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=81736"}],"version-history":[{"count":8,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/81736\/revisions"}],"predecessor-version":[{"id":85417,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/81736\/revisions\/85417"}],"wp:attachment":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=81736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=81736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=81736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}