{"id":227,"date":"2010-09-17T15:23:41","date_gmt":"2010-09-17T22:23:41","guid":{"rendered":"http:\/\/www.connorgarvey.com\/blog\/?p=227"},"modified":"2010-09-17T15:45:32","modified_gmt":"2010-09-17T22:45:32","slug":"antcall-vs-depends","status":"publish","type":"post","link":"https:\/\/connorgarvey.com\/blog\/?p=227","title":{"rendered":"Antcall vs Depends"},"content":{"rendered":"<p>Occasionally, I see issues pop up on Java projects about builds not working properly.\u00a0 They usually look like, &#8220;The build worked yesterday, but it doesn&#8217;t work today.\u00a0 I was working on it, but I didn&#8217;t change anything related to the part that is failing.&#8221; or &#8220;I can&#8217;t figure out why, when I run this by itself, it passes.\u00a0 When I run it as a part of a full build, it fails.&#8221;\u00a0 Build errors are almost always caused by a misunderstanding of the function of &#8220;depends&#8221;.<\/p>\n<h1>How Not to Use Depends<\/h1>\n<p>This probably works, but only by chance.<\/p>\n<div id=\"wpshdo_1\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_1\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_1\"><\/a><a id=\"wpshat_1\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_1\"  onClick=\"javascript:wpsh_toggleBlock(1)\" title=\"Click to show\/hide code block\">Code block<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_1\" onClick=\"javascript:wpsh_code(1)\" title=\"Show code only\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_1\" onClick=\"javascript:wpsh_print(1)\" title=\"Print code\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_1\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"xml\" style=\"font-family:monospace;\"><span class=\"sc3\"><span class=\"re1\">&lt;target<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">&quot;test&quot;<\/span> <span class=\"re0\">depends<\/span>=<span class=\"st0\">&quot;clean,compile,compile-test,test,service-test&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span><\/pre><\/div><\/div>\n<p>Depends is not a list of tasks to be executed.\u00a0 It&#8217;s a list of dependencies that must be satisfied before a target can be completed.\u00a0 Execution is not guaranteed and side effects are common.\u00a0 Take a close look at what each of the  tasks in the following script is doing.<\/p>\n<div id=\"wpshdo_2\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_2\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_2\"><\/a><a id=\"wpshat_2\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_2\"  onClick=\"javascript:wpsh_toggleBlock(2)\" title=\"Click to show\/hide code block\">Code block<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_2\" onClick=\"javascript:wpsh_code(2)\" title=\"Show code only\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_2\" onClick=\"javascript:wpsh_print(2)\" title=\"Print code\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_2\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"xml\" style=\"font-family:monospace;\"><span class=\"sc3\"><span class=\"re1\">&lt;target<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">&quot;functional-test&quot;<\/span> <span class=\"re0\">depends<\/span>=<span class=\"st0\">&quot;start-server,run-tests,stop-server&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span>\n<span class=\"sc3\"><span class=\"re1\">&lt;target<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">&quot;service-test&quot;<\/span> <span class=\"re0\">depends<\/span>=<span class=\"st0\">&quot;start-server,run-service-tests,stop-server&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span>\n<span class=\"sc3\"><span class=\"re1\">&lt;target<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">&quot;test&quot;<\/span> <span class=\"re0\">depends<\/span>=<span class=\"st0\">&quot;clean,compile,compile-test,functional-test,service-test&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span><\/pre><\/div><\/div>\n<p>To a human, the intent is obvious.<\/p>\n<ol>\n<li>Clean and compile<\/li>\n<li>Start server<\/li>\n<li>Run functional tests<\/li>\n<li>Stop server<\/li>\n<li>Start server<\/li>\n<li>Run service tests<\/li>\n<li>Stop server<\/li>\n<\/ol>\n<p>But Ant will not execute those tasks.\u00a0 Since they were declared as dependencies, Ant evaluates them as such.\u00a0 The functional tests will run as you would expect.\u00a0 When it runs the service-test target, though, it will see the start and stop server tasks <em>again<\/em>.\u00a0 As far as it&#8217;s concerned, those dependencies have already been satisfied, so it will skip start-server and stop-server.\u00a0 Ant is evaluating the script correctly, but the script is wrong.<\/p>\n<p>Dependencies are not tasks to be executed.\u00a0 They are dependencies.\u00a0 Once a dependency has been satisfied, it will not be executed again.<\/p>\n<h1>Antcall Is Not Evil<\/h1>\n<p>It exists for a reason.\u00a0 Use it when it is useful.\u00a0 Dependencies are dependencies, not task lists.\u00a0 In this case, it would be impractical to try to write the script to use depends attributes to cause events to happen correctly.\u00a0 It can be fixed very easily by using antcall.\u00a0 Each antcall is evaluated separately, so you don&#8217;t have to worry about side effects like the script above.\u00a0 It&#8217;s also easier to read.\u00a0 You can see what&#8217;s intended to happen before this target and you can see what this target is intended to do.<\/p>\n<div id=\"wpshdo_3\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_3\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_3\"><\/a><a id=\"wpshat_3\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_3\"  onClick=\"javascript:wpsh_toggleBlock(3)\" title=\"Click to show\/hide code block\">Code block<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_3\" onClick=\"javascript:wpsh_code(3)\" title=\"Show code only\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_3\" onClick=\"javascript:wpsh_print(3)\" title=\"Print code\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_3\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"xml\" style=\"font-family:monospace;\"><span class=\"sc3\"><span class=\"re1\">&lt;target<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">&quot;functional-test&quot;<\/span> <span class=\"re0\">depends<\/span>=<span class=\"st0\">&quot;start-server,run-tests,stop-server&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span>\n<span class=\"sc3\"><span class=\"re1\">&lt;target<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">&quot;service-test&quot;<\/span> <span class=\"re0\">depends<\/span>=<span class=\"st0\">&quot;start-server,run-service-tests,stop-server&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span>\n<span class=\"sc3\"><span class=\"re1\">&lt;target<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">&quot;test&quot;<\/span> <span class=\"re0\">depends<\/span>=<span class=\"st0\">&quot;clean,compile,compile-test&quot;<\/span><span class=\"re2\">&gt;<\/span><\/span>\n  <span class=\"sc3\"><span class=\"re1\">&lt;antcall<\/span> <span class=\"re0\">target<\/span>=<span class=\"st0\">&quot;functional-test&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span>\n  <span class=\"sc3\"><span class=\"re1\">&lt;antcall<\/span> <span class=\"re0\">target<\/span>=<span class=\"st0\">&quot;service-test&quot;<\/span> <span class=\"re2\">\/&gt;<\/span><\/span>\n<span class=\"sc3\"><span class=\"re1\">&lt;\/target<span class=\"re2\">&gt;<\/span><\/span><\/span><\/pre><\/div><\/div>\n<h1>Use Your Own Judgement<\/h1>\n<p>Obviously, antcall should not be used instead of depends.\u00a0 Depends is far more useful.\u00a0 But don&#8217;t throw a tool like antcall away just because it doesn&#8217;t seem as cool or concise or elegant.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Occasionally, I see issues pop up on Java projects about builds not working properly.\u00a0 They usually look like, &#8220;The build worked yesterday, but it doesn&#8217;t work today.\u00a0 I was working on it, but I didn&#8217;t change anything related to the part that is failing.&#8221; or &#8220;I can&#8217;t figure out why, when I run this by [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[59],"tags":[19,45,44,46,4],"class_list":["post-227","post","type-post","status-publish","format-standard","hentry","category-java","tag-ant","tag-antcall","tag-build","tag-depends","tag-java"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1ql2n-3F","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227"}],"version-history":[{"count":10,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions\/238"}],"wp:attachment":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}