{"id":6975,"date":"2019-10-14T01:16:49","date_gmt":"2019-10-14T01:16:49","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=6975"},"modified":"2021-11-16T06:42:57","modified_gmt":"2021-11-16T06:42:57","slug":"gradle-interview-questions-and-answer-part-1","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/gradle-interview-questions-and-answer-part-1\/","title":{"rendered":"Gradle Interview questions and Answer Part 1"},"content":{"rendered":"\n<p><strong>What are the parts of the task lifecycle<\/strong>?<\/p>\n\n\n\n<p>A. Configuration, Execution<br>\nB. Initialization, Configuration, Execution<br>\nC. Initialization, Configuration, Execution, Finalization<br>\nD. Execution<\/p>\n\n\n\n<p>Ans:  B. Initialization, Configuration, Execution<\/p>\n\n\n\n<p><strong>If I want to run a java application which plugin do I use?<\/strong><\/p>\n\n\n\n<p>A. java<br>\nB. run<br>\nC. application<br>\nD. java-runner<\/p>\n\n\n\n<p>Ans:  C. application<\/p>\n\n\n\n<p><strong>What does the wrapper task do?<\/strong><\/p>\n\n\n\n<p>A. Ensures that all developers use the same version of Gradle to build the code<br>\nB. Wraps up the code so that any exceptions are caught<br>\nC. Wraps gradle so it can be used from an IDE such as Eclipse<br>\nD. Installs an extra set of Java tasks to make testing easier<\/p>\n\n\n\n<p>Ans:  A. Ensures that all developers use the same version of Gradle to build the code<\/p>\n\n\n\n<p><strong>What is the syntax for filtering tests in gradle?<\/strong><\/p>\n\n\n\n<p>A. add a test { filter {} } closure<br>\nB. you have to run all the tests, you cannot filter<br>\nC. add the test-filter plugin<br>\nD. build only the tests you want to run<\/p>\n\n\n\n<p>Ans:  A. add a test { filter {} } closure<\/p>\n\n\n\n<p><strong>What does taskA.finalizedBy taskB do?<\/strong><\/p>\n\n\n\n<p>A. Causes taskB to run before taskA<br>\nB. Causes taskA and taskB to run in parallel<br>\nC. Nothing, this is not yet available in Gradle<br>\nD. Causes taskB to run after taskA<\/p>\n\n\n\n<p>Ans:  D. Causes taskB to run after taskA<\/p>\n\n\n\n<p><strong>When you taskA.mustRunAfter taskB<\/strong><\/p>\n\n\n\n<p>A. When you taskA.mustRunAfter taskB<br>\nB. taskA runs after taskB only if both tasks are scheduled to run<br>\nC. taskB always runs after<\/p>\n\n\n\n<p>Ans:  B. taskA runs after taskB only if both tasks are scheduled to run<\/p>\n\n\n\n<p><strong>When you call doLast on a task twice passing different closures what happens?<\/strong><\/p>\n\n\n\n<p>A. Only the first closure is executed<br>\nB. Only the last closure is executed<br>\nC. Neither closure is executed, it is an error<br>\nD. Both closures are executed<\/p>\n\n\n\n<p>Ans:  D. Both closures are executed<\/p>\n\n\n\n<p><strong>How do you add the java plugin?<\/strong><\/p>\n\n\n\n<p>A. Do nothing. The plugin is always enabled<br>\nB. apply java plugin<br>\nC. java &#8216;plugin&#8217;<br>\nD. apply plugin &#8216;java&#8217;<\/p>\n\n\n\n<p>Ans:  D. apply plugin &#8216;java&#8217;<\/p>\n\n\n\n<p><strong>When copying files you can use which method to replace text?<\/strong><\/p>\n\n\n\n<p>A. expand<br>\nB. replace<br>\nC. regex<br>\nD. insert<\/p>\n\n\n\n<p>Ans:  A. expand<\/p>\n\n\n\n<p><strong>Which of the following is valid gradle syntax to add a compile dependency on junit?<\/strong><\/p>\n\n\n\n<p>A. compile name=junit version=4.1.2<br>\nB. compile &#8216;junit:4.12&#8217;<br>\nC. compile &#8216;junit:version:4.1.12&#8217;<br>\nD. compile &#8216;junit:junit:4.1.12&#8217;<\/p>\n\n\n\n<p>Ans: D. compile &#8216;junit:junit:4.1.12&#8217;<\/p>\n\n\n\n<p><strong>What is the syntax for defining a repository in Gradle?<\/strong><\/p>\n\n\n\n<p>A. use jcenter()<br>\nB. repositories: jcenter()<br>\nC. repository: jcenter()<br>\nD. repositories { jcenter() }<\/p>\n\n\n\n<p>Ans:  D. repositories { jcenter() }<\/p>\n\n\n\n<p><strong>In a multi project build which two files do I need to add to the top level project?<\/strong><\/p>\n\n\n\n<p>A. build.gradle and build.settings<br>\nB. multi.gradle and settings.gradle<br>\nC. build.gradle and settings.properties<br>\nD. build.gradle and settings.gradle<\/p>\n\n\n\n<p>Ans:  D. build.gradle and settings.gradle<\/p>\n\n\n\n<p><strong>How do you declare a task?<\/strong><\/p>\n\n\n\n<p>A. Task.withName taskName<br>\nB. Task taskName<br>\nC. Task: taskName<br>\nD. taskName: Task<\/p>\n\n\n\n<p>Ans:  B. Task taskName<\/p>\n\n\n\n<p><strong>If you use the gradle-testsets-plugin how do you add an integrationTest sourceset in gradle?<\/strong><\/p>\n\n\n\n<p>A. testSets { integrationTest { dirName=&#8217;myDir&#8217; } }<br>\nB. testSets { dirName=&#8217;myDir&#8217;}<br>\nC. testSets { integrationTest = &#8216;myDir&#8217; }<br>\nD. integrationTest { dirName=&#8217;myDir&#8217;}<\/p>\n\n\n\n<p>Ans:  A. testSets { integrationTest { dirName=&#8217;myDir&#8217; } }<\/p>\n\n\n\n<p><strong>When you use the &lt;&lt; syntax which method on the task is executed?<\/strong><\/p>\n\n\n\n<p>A. last<br>\nB. first<br>\nC. doFirst<br>\nD. doLast<\/p>\n\n\n\n<p>Ans:  D. doLast<\/p>\n\n\n\n<p><strong>How do I tell the plugin where my Java files are if I don&#8217;t follow the Gradle convention?<\/strong><\/p>\n\n\n\n<p>A. use a sources closure<br>\nB. set a source property in the gradle build file<br>\nC. use a sourceSets closure<br>\nD. set a source property on the command line of the gradle build tool<\/p>\n\n\n\n<p>Ans:   C. use a sourceSets closure<\/p>\n\n\n\n<p><strong>How do you declare a typed task?<\/strong><\/p>\n\n\n\n<p>A. task copyImages (type: Copy)<br>\nB. task copyImages (type: Copy)<br>\nC. Copy copyImages<\/p>\n\n\n\n<p>Ans:   A. task copyImages (type: Copy)<\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_59573\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_60311\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_59573\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>What are the parts of the task lifecycle? A. Configuration, Execution B. Initialization, Configuration, Execution C. Initialization, Configuration, Execution, Finalization D. Execution Ans: B. Initialization, Configuration, Execution If I want to run a java application which plugin do I use? A. java B. run C. application D. java-runner Ans: C. application What does the wrapper&#8230;<\/p>\n","protected":false},"author":1,"featured_media":7392,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5460],"tags":[767,91,682,766,203,482],"class_list":["post-6975","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gradle","tag-answer","tag-build","tag-gradle","tag-interview","tag-job","tag-questions"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=6975"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6975\/revisions"}],"predecessor-version":[{"id":25385,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6975\/revisions\/25385"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/7392"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=6975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=6975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=6975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}