{"id":726,"date":"2021-12-09T23:35:35","date_gmt":"2021-12-09T15:35:35","guid":{"rendered":"https:\/\/blog.cauchyschwarz.com\/?p=726"},"modified":"2021-12-09T23:35:38","modified_gmt":"2021-12-09T15:35:38","slug":"gradle-2","status":"publish","type":"post","link":"https:\/\/blog.cauchyschwarz.com\/?p=726","title":{"rendered":"gradle"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e251e5075f3\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e251e5075f3\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3\" >\u5b98\u65b9\u6587\u6863<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#Features\" >Features<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%AE%89%E8%A3%85Gradle\" >\u5b89\u88c5Gradle<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%9C%A8%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B8%AD%E4%BD%BF%E7%94%A8Gradle\" >\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528Gradle<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#Gradle_Wrapper\" >Gradle Wrapper<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E7%94%9F%E6%88%90gradle_wrapper\" >\u751f\u6210gradle wrapper<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#Gradle_Daemon\" >Gradle Daemon<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#gradle%E7%9A%84%E4%BE%9D%E8%B5%96%E7%AE%A1%E7%90%86\" >gradle\u7684\u4f9d\u8d56\u7ba1\u7406<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%A3%B0%E6%98%8E%E4%BE%9D%E8%B5%96\" >\u58f0\u660e\u4f9d\u8d56<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E4%BE%9D%E8%B5%96%E9%85%8D%E7%BD%AEDependency_configurations\" >\u4f9d\u8d56\u914d\u7f6e(Dependency configurations)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%A3%B0%E6%98%8E%E5%A4%96%E9%83%A8%E4%BE%9D%E8%B5%96\" >\u58f0\u660e\u5916\u90e8\u4f9d\u8d56<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E4%BB%93%E5%BA%93Repositories\" >\u4ed3\u5e93(Repositories)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%8F%91%E5%B8%83%E4%BD%9C%E5%93%81Publishing_artifacts\" >\u53d1\u5e03\u4f5c\u54c1(Publishing artifacts)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E7%9A%84%E6%9E%84%E5%BB%BA\" >\u591a\u9879\u76ee\u5de5\u7a0b\u7684\u6784\u5efa<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E6%9E%84%E5%BB%BA%E7%9A%84%E7%BB%93%E6%9E%84Structure_of_a_multi-project_build\" >\u591a\u9879\u76ee\u5de5\u7a0b\u6784\u5efa\u7684\u7ed3\u6784(Structure of a multi-project build)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E6%89%A7%E8%A1%8C%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E7%9A%84%E6%9E%84%E5%BB%BA\" >\u6267\u884c\u591a\u9879\u76ee\u5de5\u7a0b\u7684\u6784\u5efa<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E6%8C%81%E7%BB%AD%E6%9E%84%E5%BB%BAContinuous_build\" >\u6301\u7eed\u6784\u5efa(Continuous build)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E7%BB%84%E5%90%88%E6%9E%84%E5%BB%BAComposite_build\" >\u7ec4\u5408\u6784\u5efa(Composite build)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E6%9E%84%E5%BB%BA%E7%8E%AF%E5%A2%83%E7%9A%84%E8%AE%BE%E7%BD%AE\" >\u6784\u5efa\u73af\u5883\u7684\u8bbe\u7f6e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E6%9E%84%E5%BB%BA%E7%BC%93%E5%AD%98Build_Cache\" >\u6784\u5efa\u7f13\u5b58(Build Cache)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=726\/#%E7%BC%96%E5%86%99Gradle%E8%84%9A%E6%9C%AC\" >\u7f16\u5199Gradle\u811a\u672c<\/a><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\" id=\"%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3\"><span class=\"ez-toc-section\" id=\"%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3\"><\/span><a href=\"https:\/\/docs.gradle.org\/current\/userguide\/userguide.html\">\u5b98\u65b9\u6587\u6863<\/a><span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"features\"><span class=\"ez-toc-section\" id=\"Features\"><\/span>Features<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>Declarative builds and build-by-convention<\/li><li>Language for dependency based programming<\/li><li>Structure your build<\/li><li>Deep API<\/li><li>Gradle scales<\/li><li>Multi-project builds<\/li><li>Many ways to manage your dependencies<\/li><li>Gradle is the first build integration tool<\/li><li>Ease of migration<\/li><li>Groovy<br>Gradle\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u662fGroovy\u3002<\/li><li>The Gradle wrapper<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%AE%89%E8%A3%85gradle\"><span class=\"ez-toc-section\" id=\"%E5%AE%89%E8%A3%85Gradle\"><\/span>\u5b89\u88c5Gradle<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%9C%A8%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B8%AD%E4%BD%BF%E7%94%A8gradle\"><span class=\"ez-toc-section\" id=\"%E5%9C%A8%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B8%AD%E4%BD%BF%E7%94%A8Gradle\"><\/span>\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528Gradle<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">task compile {\n    doLast {\n        println 'compiling source'\n    }\n}\n\ntask compileTest(dependsOn: compile) {\n    doLast {\n        println 'compiling unit tests'\n    }\n}\n\ntask test(dependsOn: [compile, compileTest]) {\n    doLast {\n        println 'running unit tests'\n    }\n}\n\ntask dist(dependsOn: [compile, test]) {\n    doLast {\n        println 'building the distribution'\n    }\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u60f3\u8981\u8fd0\u884c\u67d0\u4e2atask\u65f6\uff0c\u76f4\u63a5\u8f93\u547d\u4ee4\uff1a<code>gradle taskname<\/code>\u3002gradle\u4f1a\u6309\u7167task\u7684\u4f9d\u8d56\u5173\u7cfb\u6309\u987a\u5e8f\u6267\u884c\u9700\u8981\u8fd0\u884c\u7684task\u3002<\/li><li><code>gradle task1 -x task2<\/code>\u8868\u793a\u6267\u884ctask1\u53ca\u5176\u4f9d\u8d56\u7684task\uff0c\u4f46\u662f\u4e0d\u6267\u884ctask2\u3002<\/li><li><code>--continue<\/code>\u9009\u9879\u5219\u8868\u793a\u9047\u5230\u9519\u8bef\u4e0d\u8981\u505c\u6b62\u800c\u662f\u7ee7\u7eed\u6267\u884c\u8be5\u6267\u884c\u7684task\u3002<\/li><li>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165task\u7684\u540d\u5b57\u65f6\u4e0d\u9700\u8981\u8f93\u5168\u540d\uff0c\u53ef\u4ee5\u53ea\u8f93\u5165\u8db3\u591f\u7684\u53ef\u4ee5\u552f\u4e00\u786e\u5b9atask\u7684\u5f00\u5934\u51e0\u4e2a\u5b57\u6bcd\uff0c\u6216\u8005\u53ea\u8f93\u5165\u9a7c\u5cf0\u5f0f\u7684\u540d\u5b57\u7684\u5f00\u5934\u5b57\u6bcd(\u6bd4\u5982\u7528cT\u8868\u793acompileTest)\u3002<\/li><li>\u4f7f\u7528<code>-b<\/code>\u9009\u9879\u9009\u62e9\u8981\u4f7f\u7528\u7684gradle\u6587\u4ef6\u3002\u6267\u884cgradle\u547d\u4ee4\u65f6\uff0c\u9ed8\u8ba4\u5728\u5f53\u524d\u76ee\u5f55\u5bfb\u627ebuild.gradle\u6587\u4ef6\uff0c\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u7528<code>-b<\/code>\u9009\u9879\u624b\u52a8\u6307\u5b9a\u4e00\u4e2agradle\u6587\u4ef6\u3002\u5f53\u7528<code>-b<\/code>\u9009\u9879\u6307\u5b9agradle\u6587\u4ef6\u65f6\uff0c<em>settings.gradle<\/em>\u5931\u6548\u3002<\/li><li>\u7c7b\u4f3cmake\u7684\u5de5\u4f5c\u539f\u7406\uff0cgralde\u5728\u6267\u884c\u67d0\u4e9btask\u65f6\u53ef\u80fd\u4f1a\u6839\u636e\u4f9d\u8d56\u5173\u7cfb\u8ba4\u4e3a\u4e0d\u9700\u8981\u771f\u7684\u53bb\u8dd1\u8fd9\u4e2atask\uff0c\u4e3a\u4e86\u5f3a\u5236\u5730\u91cd\u65b0\u8dd1\u8fd9\u79cdtask\uff0c\u9700\u8981\u52a0\u4e0a<code>--rerun-tasks<\/code>\u9009\u9879\u3002<\/li><li><code>-q<\/code>\u9009\u9879\u4e0d\u8f93\u51fa\u4e00\u4e9b\u4e0d\u91cd\u8981\u7684\u4fe1\u606f\uff0c\u5b89\u9759\u6a21\u5f0f\u3002<\/li><li><code>gradle projects<\/code>\u8f93\u51fa\u5b50\u5de5\u7a0b\u3002<\/li><li><code>gradle tasks<\/code>\u5217\u51fa\u6240\u6709\u7684task\u3002<code>gradle tasks --all<\/code>\u66f4\u8fdb\u4e00\u6b65\u5730\u5217\u51fa\u4e86\u4e00\u4e9b\u4f9d\u8d56\u7684task\u3002<\/li><li><code>gradle help --task taskname<\/code>\u5217\u51fataskname\u8fd9\u4e2atask\u7684\u76f8\u5173\u4fe1\u606f\u3002<\/li><li><code>gradle dependencies<\/code>&nbsp;\u5217\u51fa\u5de5\u7a0b\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/li><li><code>gradle buildEnvironment<\/code>&nbsp;\u5217\u51fagradle\u811a\u672c\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/li><li><code>gradle properties<\/code>\u5217\u51fa\u5de5\u7a0b\u5c5e\u6027<\/li><li><code>--profile<\/code>\u9009\u9879\uff0c\u6dfb\u52a0\u7528\u65f6\u7edf\u8ba1\uff0c\u8fdb\u884cprofiling\u3002<\/li><li><code>-m<\/code>\u9009\u9879\uff0c\u7c7b\u4f3c\u4e8e\u67e5\u770b\u67d0\u4e2atask\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"gradle-wrapper\"><span class=\"ez-toc-section\" id=\"Gradle_Wrapper\"><\/span>Gradle Wrapper<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u6709\u65f6\u7528\u6237\u53ef\u80fd\u6ca1\u6709\u88c5gradle\u6216\u8005\u88c5\u7684gradle\u7248\u672c\u4e0d\u7b26\u5408\u8981\u6c42\uff0cgradle wrapper\u6587\u4ef6\u5c31\u662f\u7528\u6765\u89e3\u51b3\u8fd9\u79cd\u95ee\u9898\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E7%94%9F%E6%88%90gradle-wrapper\"><span class=\"ez-toc-section\" id=\"%E7%94%9F%E6%88%90gradle_wrapper\"><\/span>\u751f\u6210gradle wrapper<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>\u901a\u8fc7\u547d\u4ee4\u751f\u6210\uff1a<code>gradle wrapper --gradle-version 2.0<\/code>\u3002<\/li><li>\u901a\u8fc7\u5728build.gradle\u4e2d\u6dfb\u52a0\u4e00\u4e2aWrapper task\uff0c\u7136\u540e\u6267\u884c\u8fd9\u4e2atask\u751f\u6210\uff1a<code>task wrapper(type: Wrapper) { gradleVersion = '2.0' }<\/code><\/li><\/ol>\n\n\n\n<p>\u751f\u6210\u4e86\u6240\u8c13\u7684gradle wrapper\u4e4b\u540e\uff0c\u9879\u76ee\u6587\u4ef6\u5939\u5185\u4f1a\u591a\u51fa\u4ee5\u4e0b\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">gradlew(Unix Shell script)\ngradlew.bat(Windows batch file)\ngradle\/wrapper\/\n    gradle-wrapper.jar(Wrapper JAR)\n    gradle-wrapper.properties(Wrapper properties)\n<\/code><\/pre>\n\n\n\n<p>\u6709\u4e86gradle wrapper\u4e4b\u540e\uff0c\u5728\u8fd0\u884c\u76f8\u5e94\u7684task\u7684\u65f6\u5019\uff0c\u5c31\u4e0d\u518d\u7528gradle\u547d\u4ee4\u800c\u6539\u4e3agradlew\u6216\u8005gradlew.bat\u547d\u4ee4\u3002\u76f8\u5e94\u7684gradle\u7248\u672c\u4f1a\u88ab\u4e0b\u8f7d\u5230\u76ee\u5f55*$USER_HOME\/.gradle\/wrapper\/dists*\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8egradle.properties\u8fd9\u4e2a\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u4fee\u6539\u5176\u4e2d\u7684gradle\u6587\u4ef6\u7684\u4e0b\u8f7d\u5730\u5740\uff0c\u6dfb\u52a0\u4e0b\u8f7d\u65f6\u53ef\u80fd\u9700\u8981\u7684\u8ba4\u8bc1\u8fc7\u7a0b\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u6216\u8005\u8bbe\u7f6e\u8981\u4e0b\u8f7d\u7684gradle\u7248\u672c\u7684SHA-256\u503c\u3002\u5177\u4f53\u64cd\u4f5c\u89c1\u5b98\u65b9\u6587\u6863\u7b2c6\u7ae0\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"gradle-daemon\"><span class=\"ez-toc-section\" id=\"Gradle_Daemon\"><\/span>Gradle Daemon<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>gradle\u7a0b\u5e8f\u6bcf\u6b21\u542f\u52a8\u65f6\u90fd\u8981\u521d\u59cb\u5316JVM\u548c\u8f7d\u5165\u4e00\u5806\u76f8\u5e94\u7684\u5e93\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u9700\u8981\u82b1\u8d39\u76f8\u5f53\u7684\u65f6\u95f4\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5728\u540e\u53f0\u8dd1\u4e00\u4e2a\u4e00\u76f4\u5728\u8fd0\u884c\u7740\u7684gradle\u5b88\u62a4\u8fdb\u7a0b\u6765\u51cf\u5c11\u8fd9\u6837\u7684\u542f\u52a8\u65f6\u95f4\u7684\u6d88\u8017\uff0c\u63d0\u9ad8gradle\u7684\u6267\u884c\u6548\u7387\u3002\u4e0d\u8fc7\u8fd9\u4e2agradle daemon\u529f\u80fd\u662f\u4ece3.0\u7248\u672c\u624d\u5f00\u59cb\u6709\u7684\uff0c\u5177\u4f53\u76f8\u5173\u7528\u6cd5\u67e5\u770b\u5b98\u65b9\u6587\u6863\u7b2c7\u7ae0\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"gradle%E7%9A%84%E4%BE%9D%E8%B5%96%E7%AE%A1%E7%90%86\"><span class=\"ez-toc-section\" id=\"gradle%E7%9A%84%E4%BE%9D%E8%B5%96%E7%AE%A1%E7%90%86\"><\/span>gradle\u7684\u4f9d\u8d56\u7ba1\u7406<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u4f9d\u8d56\u4e3b\u8981\u5305\u542b\u4e24\u90e8\u5206\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>dependencies<br>\u4e3a\u4e86\u6784\u5efa\u6216\u8005\u8fd0\u884c\u9879\u76ee\u800c\u9700\u8981\u7684\u4e1c\u897f(incoming)\uff1b<\/li><li>publications<br>\u9879\u76ee\u7684\u4ea7\u51fa\uff0c\u4f1a\u62ff\u6765\u53d1\u5e03\u6216\u8005\u4e0a\u4f20\u7684\u4e1c\u897f(outgoing)\uff1b<\/li><\/ul>\n\n\n\n<p>dependencies resolution\uff1btransitive dependencies\uff1b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%A3%B0%E6%98%8E%E4%BE%9D%E8%B5%96\"><span class=\"ez-toc-section\" id=\"%E5%A3%B0%E6%98%8E%E4%BE%9D%E8%B5%96\"><\/span>\u58f0\u660e\u4f9d\u8d56<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u58f0\u660e\u4f9d\u8d56\u7684\u7b80\u5355\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">apply plugin: 'java'\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'\n    testCompile group: 'junit', name: 'junit', version: '4.+'\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E4%BE%9D%E8%B5%96%E9%85%8D%E7%BD%AEdependency-configurations\"><span class=\"ez-toc-section\" id=\"%E4%BE%9D%E8%B5%96%E9%85%8D%E7%BD%AEDependency_configurations\"><\/span>\u4f9d\u8d56\u914d\u7f6e(Dependency configurations)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e00\u4e2a\u4f9d\u8d56\u914d\u7f6e\u662f\u6307\u7684\u4e00\u4e2a\u6709\u540d\u5b57\u7684\u4f9d\u8d56\u548cartifacts\u7684\u96c6\u5408\u3002\u4f9d\u8d56\u914d\u7f6e\u7684\u4f5c\u7528\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u58f0\u660e\u4f9d\u8d56<\/li><li>\u89e3\u51b3\u4f9d\u8d56<\/li><li>\u66b4\u9732\u63a5\u53e3?(Exposing Artifacts for Consumption)<br>The plugin uses configurations to define what artifacts it generates for other projects to consume\u3002<\/li><\/ol>\n\n\n\n<p>\u51e0\u79cd\u7531Java Library Plugin\u5b9a\u4e49\u597d\u7684\u4f9d\u8d56\u914d\u7f6e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>implementation<\/li><li>runtimeClasspath<\/li><li>apiElements<\/li><\/ul>\n\n\n\n<p>\u5173\u4e8e<a href=\"https:\/\/docs.gradle.org\/current\/userguide\/java_library_plugin.html#sec:java_library_configurations_graph\">Java Library Plugin\u63d0\u4f9b\u7684\u66f4\u591a\u914d\u7f6e\u53ca\u7ec6\u8282<\/a>\u3001\u4ee5\u53ca\u66f4\u591a\u7684<a href=\"https:\/\/docs.gradle.org\/current\/userguide\/dependency_management.html#sub:configurations\">Plugin\u548c\u76f8\u5e94\u7684\u914d\u7f6e\u7ec6\u8282<\/a>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%A3%B0%E6%98%8E%E5%A4%96%E9%83%A8%E4%BE%9D%E8%B5%96\"><span class=\"ez-toc-section\" id=\"%E5%A3%B0%E6%98%8E%E5%A4%96%E9%83%A8%E4%BE%9D%E8%B5%96\"><\/span>\u58f0\u660e\u5916\u90e8\u4f9d\u8d56<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">dependencies {\n    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'\n}\n<\/code><\/pre>\n\n\n\n<p>\u7b80\u5316\u7248\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">dependencies {\n    compile 'org.hibernate:hibernate-core:3.6.7.Final'\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E4%BB%93%E5%BA%93repositories\"><span class=\"ez-toc-section\" id=\"%E4%BB%93%E5%BA%93Repositories\"><\/span>\u4ed3\u5e93(Repositories)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">repositories {\n    mavenCentral()\n}\n\nrepositories {\n    jcenter()\n}\n\nrepositories {\n    maven {\n        url \"http:\/\/repo.mycompany.com\/maven2\"\n    }\n}\n\nrepositories {\n    ivy {\n        url \"http:\/\/repo.mycompany.com\/repo\"\n    }\n}\n\nrepositories {\n    ivy {\n        <em>\/\/ URL can refer to a local directory<\/em>\n        url \"..\/local-repo\"\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u4e00\u4e2a\u9879\u76ee\u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a\u4ed3\u5e93\uff0cGradle\u4f1a\u6309\u987a\u5e8f\u6328\u7740\u5728\u8fd9\u4e9b\u4ed3\u5e93\u5bfb\u627e\u4f9d\u8d56\uff0c\u76f4\u5230\u627e\u5230\u9700\u8981\u7684\u4f9d\u8d56\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%8F%91%E5%B8%83%E4%BD%9C%E5%93%81publishing-artifacts\"><span class=\"ez-toc-section\" id=\"%E5%8F%91%E5%B8%83%E4%BD%9C%E5%93%81Publishing_artifacts\"><\/span>\u53d1\u5e03\u4f5c\u54c1(Publishing artifacts)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e0a\u4f20\u5230Ivy repository\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">uploadArchives {\n    repositories {\n        ivy {\n            credentials {\n                username \"username\"\n                password \"pw\"\n            }\n            url \"http:\/\/repo.mycompany.com\"\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\u4e0a\u4f20\u5230Maven repository\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">apply plugin: 'maven'\n\nuploadArchives {\n    repositories {\n        mavenDeployer {\n            repository(url: \"file:\/\/localhost\/tmp\/myRepo\/\")\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E7%9A%84%E6%9E%84%E5%BB%BA\"><span class=\"ez-toc-section\" id=\"%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E7%9A%84%E6%9E%84%E5%BB%BA\"><\/span>\u591a\u9879\u76ee\u5de5\u7a0b\u7684\u6784\u5efa<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E6%9E%84%E5%BB%BA%E7%9A%84%E7%BB%93%E6%9E%84structure-of-a-multi-project-build\"><span class=\"ez-toc-section\" id=\"%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E6%9E%84%E5%BB%BA%E7%9A%84%E7%BB%93%E6%9E%84Structure_of_a_multi-project_build\"><\/span>\u591a\u9879\u76ee\u5de5\u7a0b\u6784\u5efa\u7684\u7ed3\u6784(Structure of a multi-project build)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8fd9\u6837\u7684\u6784\u5efa\u4e00\u822c\u5177\u6709\u5982\u4e0b\u7279\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5728\u6839\u76ee\u5f55\u6216\u8005master\u76ee\u5f55\u91cc\u6709\u4e00\u4e2asettings.gradle\u6587\u4ef6<\/li><li>\u5728\u6839\u76ee\u5f55\u6216\u8005master\u76ee\u5f55\u91cc\u6709\u4e00\u4e2abuild.gradle\u6587\u4ef6<\/li><li>\u5728\u5b50\u76ee\u5f55\u4e2d\u6709\u7740\u5404\u81ea\u7684\u7684*.gradle\u6587\u4ef6\u3002<\/li><\/ul>\n\n\n\n<p>settings.gradle\u6587\u4ef6\u544a\u8bc9Gralde\u6b21\u9879\u76ee\u662f\u5982\u4f55\u4e0e\u5b50\u9879\u76ee\u8054\u7cfb\u5728\u4e00\u8d77\u7684\u3002\u53ef\u4ee5\u901a\u8fc7\u8bfb\u8fd9\u4e2a\u6587\u4ef6\u6216\u8005\u8fd0\u884c<code>gradle -q projects<\/code>\u547d\u4ee4\u6765\u4e86\u89e3\u9879\u76ee\u4e0e\u5b50\u9879\u76ee\u7684\u7ed3\u6784\u3002<br>\u4e00\u4e2a\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&gt; gradle -q projects\n\n------------------------------------------------------------\nRoot project\n------------------------------------------------------------\n\nRoot project 'multiproject'\n+--- Project ':api'\n+--- Project ':services'\n|    +--- Project ':services:shared'\n|    \\--- Project ':services:webservice'\n\\--- Project ':shared'\n\nTo see a list of the tasks of a project, run gradle &lt;project-path&gt;:tasks\nFor example, try running gradle :api:tasks\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E6%89%A7%E8%A1%8C%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E7%9A%84%E6%9E%84%E5%BB%BA\"><span class=\"ez-toc-section\" id=\"%E6%89%A7%E8%A1%8C%E5%A4%9A%E9%A1%B9%E7%9B%AE%E5%B7%A5%E7%A8%8B%E7%9A%84%E6%9E%84%E5%BB%BA\"><\/span>\u6267\u884c\u591a\u9879\u76ee\u5de5\u7a0b\u7684\u6784\u5efa<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>cd\u5230\u5b50\u9879\u76ee\u76ee\u5f55\u91cc\uff0c\u7136\u540e\u6309\u7167\u4e00\u822c\u7684\u9879\u76ee\u6267\u884ctask\u7684\u65b9\u5f0f\uff0c\u7528<code>gradle &lt;task&gt;<\/code>\u547d\u4ee4\u6267\u884ctask\u3002\u4f46\u662f\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cgradle\u4f1a\u6267\u884c\u5f53\u524d\u76ee\u5f55\u53ca\u5176\u5b50\u76ee\u5f55\u6240\u5305\u542b\u9879\u76ee\u7684\u6240\u6709\u540d\u4e3atask\u7684task\u3002<\/li><li>\u5728\u6839\u76ee\u5f55\u4f7f\u7528\u5b8c\u6574\u7684task\u7684\u540d\u5b57\u6267\u884ctask\uff1a<code>gradle :services:webservice:build<\/code>\u3002<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%8C%81%E7%BB%AD%E6%9E%84%E5%BB%BAcontinuous-build\"><span class=\"ez-toc-section\" id=\"%E6%8C%81%E7%BB%AD%E6%9E%84%E5%BB%BAContinuous_build\"><\/span>\u6301\u7eed\u6784\u5efa(Continuous build)<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u6301\u7eed\u6784\u5efa\u662f\u8fd8\u5728\u53d1\u5c55\u4e2d\u7684\u7279\u6027,Gradle\u8fd8\u6ca1\u6709\u5b8c\u5584\u5730\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7279\u6027\u3002<br>\u6301\u7eed\u6784\u5efa\uff1a\u5bf9\u4e8e\u4e00\u4e2a\u6784\u5efa\u76ee\u6807\/\u8bf7\u6c42\uff0cGradle\u80fd\u591f\u4e0d\u65ad\u5730\u68c0\u6d4b\u4e4b\u524d\u7684\u6784\u5efa\u662f\u5426\u8fc7\u671f\uff0c\u5982\u679c\u8fc7\u671f\u5c31\u6267\u884c\u76f8\u5e94\u7684\u6784\u5efa\u64cd\u4f5c\u3002<br>\u6709\u7a7a\u518d\u6765\u8bfb\u8fd9\u5b98\u65b9\u6587\u6863\u7684\u7b2c10\u7ae0\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E7%BB%84%E5%90%88%E6%9E%84%E5%BB%BAcomposite-build\"><span class=\"ez-toc-section\" id=\"%E7%BB%84%E5%90%88%E6%9E%84%E5%BB%BAComposite_build\"><\/span>\u7ec4\u5408\u6784\u5efa(Composite build)<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%9E%84%E5%BB%BA%E7%8E%AF%E5%A2%83%E7%9A%84%E8%AE%BE%E7%BD%AE\"><span class=\"ez-toc-section\" id=\"%E6%9E%84%E5%BB%BA%E7%8E%AF%E5%A2%83%E7%9A%84%E8%AE%BE%E7%BD%AE\"><\/span>\u6784\u5efa\u73af\u5883\u7684\u8bbe\u7f6e<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u4e3b\u8981\u662f\u901a\u8fc7\u4fee\u6539gradle.properties\u8fd9\u4e2a\u6587\u4ef6\u6765\u914d\u7f6e\u6784\u5efa\u73af\u5883\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%9E%84%E5%BB%BA%E7%BC%93%E5%AD%98build-cache\"><span class=\"ez-toc-section\" id=\"%E6%9E%84%E5%BB%BA%E7%BC%93%E5%AD%98Build_Cache\"><\/span>\u6784\u5efa\u7f13\u5b58(Build Cache)<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E7%BC%96%E5%86%99gradle%E8%84%9A%E6%9C%AC\"><span class=\"ez-toc-section\" id=\"%E7%BC%96%E5%86%99Gradle%E8%84%9A%E6%9C%AC\"><\/span>\u7f16\u5199Gradle\u811a\u672c<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u7531\u4e8e\u8fd9\u90e8\u5206\u5185\u5bb9\u592a\u591a\uff0c\u6240\u4ee5\u91cd\u65b0\u5199\u4e00\u7bc7\u5427\u6765\u63cf\u8ff0\u8fd9\u90e8\u5206\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u65b9\u6587\u6863 Features Declarative builds and build-by-convention Language for dependency based programming S&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[49],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-10","tag-gradle"],"_links":{"self":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=726"}],"version-history":[{"count":1,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions\/727"}],"wp:attachment":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}