{"id":3600,"date":"2019-10-09T16:33:26","date_gmt":"2019-10-09T16:33:26","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=3600"},"modified":"2019-12-31T16:44:05","modified_gmt":"2019-12-31T16:44:05","slug":"gradle-basics","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/gradle-basics\/","title":{"rendered":"Gradle Basics"},"content":{"rendered":"<ol>\n<li>Gradle is Partly Declarative and Partly Programmatic and Uses Domain Specific Language(DSL) coded in groovy or kotlin in build.gradle <\/li>\n<li>Gradle Parses build.gradle file and constructs DAG(Directed Acyclic Graph) and constructs a graph of task<\/li>\n<li>Gradle executes tasks in order.If ouput of task is same as last output, then task wont be executed<\/li>\n<li>Gradle manages trasitive dependency on its own(Similar to maven) and gradle uses repositories.<\/li>\n<li>Gradle updates to new version of Dependencies<\/li>\n<\/ol>\n<p>Teardown of <strong>build.gradle<\/strong> file <\/p>\n<ol>\n<li>To make gradle, java aware we need to add apply plugin:&#8217;java&#8217; <\/li>\n<li>Once the above line is added, the following tasks get tagged to project &#8211; clean, assemble, compile, test<\/li>\n<li>dependencies and repositories are added in flower bracket like one below<\/li>\n<li>under dependencies we can have multiple tasks. In the below code <em>compile<\/em> is added as a task<\/li>\n<\/ol>\n<p><strong>build.gradle<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ngroup 'com.mugil.employeeManagement'\r\nversion '1.0-Snapshot'\r\n\r\napply plugin: 'java'\r\n\r\nsourceCompatibility=1.8\r\n\r\nrepositories {    \r\n    mavenCentral()\r\n}\r\n\r\ndependencies {\r\n\tcompile 'com.google.code.gson:gson:2.8.4'\r\n}\r\n<\/pre>\n<p><strong>What is the Difference between gradlew and gradle?<\/strong><\/p>\n<p>gradlew is a wrapper(w &#8211; character) that uses gradle.<\/p>\n<p><em>Under the hood gradlew performs three main things:<\/em><\/p>\n<ol>\n<li>Download and install the correct gradle version<\/li>\n<li>Parse the arguments<\/li>\n<li>Call a gradle task<\/li>\n<\/ol>\n<p>Using Gradle Wrapper we can distribute\/share a project to everybody to use the same version and Gradle&#8217;s functionality(compile, build, install&#8230;) even if it has not been installed.<\/p>\n<p>To create a wrapper run:<\/p>\n<pre>\r\ngradle wrapper\r\n<\/pre>\n<p>This command generate:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2019\/12\/3U62J.png\" alt=\"\" height=\"598\" width=\"419\"\/><\/p>\n<p><em>gradle-wrapper.properties<\/em> will contain the information about the Gradle distribution<\/p>\n<p><strong>How to skip Gradle Test?<\/strong><\/p>\n<pre>\r\ngradle build -x test \r\n<\/pre>\n<p><strong>How to supply Argument to Spring Controller during application startup in Gradle Wrapper <\/strong><\/p>\n<pre>\r\ngradlew bootRun --args='--welcome.message=Mugil'\r\n<\/pre>\n<p><strong>WelcomeController.java<\/strong><br \/>\nIn the below code welcomeMsg variable is assigned value during application startup. In similar ways environment variables could be setup<br \/>\nby supplying arguments as parameters while executing gradlew bootrun <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class WelcomeController {\r\n    public String welcomeMsg;\r\n\r\n    @Autowired\r\n    public WelcomeController(@Value(&quot;${welcome.message}&quot;) String message) {\r\n        welcomeMsg = message;\r\n        System.out.println(&quot;Hi &quot;+ message);\r\n    }\r\n\r\n    @GetMapping(&quot;\/&quot;)\r\n    public String sayHello() {\r\n        return &quot;Mugil&quot;;\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Gradle is Partly Declarative and Partly Programmatic and Uses Domain Specific Language(DSL) coded in groovy or kotlin in build.gradle Gradle Parses build.gradle file and constructs DAG(Directed Acyclic Graph) and constructs a graph of task Gradle executes tasks in order.If ouput of task is same as last output, then task wont be executed Gradle manages trasitive&hellip; <a href=\"https:\/\/codethataint.com\/blog\/gradle-basics\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[290],"tags":[],"class_list":["post-3600","post","type-post","status-publish","format-standard","hentry","category-basics-gradle"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=3600"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3600\/revisions"}],"predecessor-version":[{"id":3633,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3600\/revisions\/3633"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=3600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=3600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=3600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}