{"id":4619,"date":"2024-11-01T11:36:11","date_gmt":"2024-11-01T03:36:11","guid":{"rendered":"https:\/\/qaqaq.top\/?p=4619"},"modified":"2024-11-06T11:14:23","modified_gmt":"2024-11-06T03:14:23","slug":"gradle-%e8%bf%9b%e9%98%b6%e8%af%b4%e6%98%8e-build-gradle-%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=4619","title":{"rendered":"Gradle \u8fdb\u9636\u8bf4\u660e-build.gradle \u6587\u4ef6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">7\u3001build.gradle \u6587\u4ef6<\/h2>\n\n\n\n<p>build.gradle \u662f\u4e00\u4e2a gradle \u7684\u6784\u5efa\u811a\u672c\u6587\u4ef6,\u652f\u6301 java\u3001groovy \u7b49\u8bed\u8a00\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e2a project \u90fd\u4f1a\u6709\u4e00\u4e2a build.gradle \u6587\u4ef6,\u8be5\u6587\u4ef6\u662f\u9879\u76ee\u6784\u5efa\u7684\u5165\u53e3,\u53ef\u914d\u7f6e\u7248\u672c\u3001\u63d2\u4ef6\u3001\u4f9d\u8d56\u5e93\u7b49\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e2a build \u6587\u4ef6\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684 Project \u5b9e\u4f8b,\u5bf9 build.gradle \u6587\u4ef6\u914d\u7f6e\uff0c\u672c\u8d28\u5c31\u662f\u8bbe\u7f6e Project \u5b9e\u4f8b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u6bcf\u4e2a project \u90fd\u4f1a\u6709\u4e00\u4e2a build \u6587\u4ef6,\u90a3\u4e48 Root Project \u4e5f\u4e0d\u5217\u5916. Root Project \u53ef\u4ee5\u83b7\u53d6\u5230\u6240\u6709 Child Project,\u6240\u4ee5\u5728 Root Project \u7684 build \u6587\u4ef6\u4e2d\u6211\u4eec\u53ef\u4ee5\u5bf9 Child Project \u7edf\u4e00\u914d\u7f6e,\u6bd4\u5982\u5e94\u7528\u7684\u63d2\u4ef6\u3001\u4f9d\u8d56\u7684maven \u4e2d\u5fc3\u4ed3\u5e93\u7b49\u3002<\/p>\n\n\n\n<p>build \u6587\u4ef6\u4e2d\u5e38\u89c1\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/qaqaq.top\/wp-content\/uploads\/2024\/11\/image.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"898\" height=\"508\" data-original=\"https:\/\/qaqaq.top\/wp-content\/uploads\/2024\/11\/image.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-4621\"  sizes=\"(max-width: 898px) 100vw, 898px\" \/><\/div><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6211\u7684\u4ee3\u7801<\/p>\n\n\n\n<p>build.gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5bf9\u5f53\u524d\u5de5\u7a0b\u53ca\u5b50\u5de5\u7a0b\u90fd\u505a\u8bbe\u7f6e\nallprojects {\n\n}\n\/\/\u5bf9\u5b50\u5de5\u7a0b\u90fd\u505a\u8bbe\u7f6e\nsubprojects {\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1\u3001\u5e38\u89c1\u5c5e\u6027\u4ee3\u7801<\/h3>\n\n\n\n<p id=\"064632b0e4b22eb57e23a5aa690d0f02\">\u4ee3\u7801\u53c2\u8003\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\u6307\u5b9a\u4f7f\u7528\u4ec0\u4e48\u7248\u672c\u7684JDK\u8bed\u6cd5\u7f16\u8bd1\u6e90\u4ee3\u7801,\u8ddf\u7f16\u8bd1\u73af\u5883\u6709\u5173,\u5728\u6709java\u63d2\u4ef6\u65f6\u624d\u80fd\u7528\nsourceCompatibility = 1.8\n\/\/\u6307\u5b9a\u751f\u6210\u7279\u5b9a\u4e8e\u67d0\u4e2aJDK\u7248\u672c\u7684class\u6587\u4ef6:\u8ddf\u8fd0\u884c\u73af\u5883\u6709\u5173,\u5728\u6709java\u63d2\u4ef6\u65f6\u624d\u80fd\u7528\ntargetCompatibility = 1.8\n\/\/\u4e1a\u52a1\u7f16\u7801\u5b57\u7b26\u96c6,\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6e90\u7801\u89e3\u7801\u7684\u5b57\u7b26\u96c6&#91;\u7f16\u8bd1\u5668] \ncompileJava.options.encoding \"UTF-8\"\n\/\/\u6d4b\u8bd5\u7f16\u7801\u5b57\u7b26\u96c6,\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6e90\u7801\u89e3\u7801\u7684\u5b57\u7b26\u96c6&#91;\u7f16\u8bd1\u5668] \ncompileTestJava.options.encoding \"UTF-8\"\n\/\/\u7f16\u8bd1JAVA\u6587\u4ef6\u65f6\u91c7\u7528UTF-8:\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6e90\u7801\u7f16\u7801\u7684\u5b57\u7b26\u96c6\u3010\u6e90\u6587\u4ef6\u3011\ntasks.withType(JavaCompile) {\n    options.encoding = \"UTF-8\"\n}\n\/\/\u7f16\u8bd1JAVA\u6587\u4ef6\u65f6\u91c7\u7528UTF-8:\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6587\u6863\u7f16\u7801\u7684\u5b57\u7b26\u96c6\u3010\u6e90\u6587\u4ef6\u3011\ntasks.withType(Javadoc) {\n    options.encoding = \"UTF-8\"\n}<\/code><\/pre>\n\n\n\n<p id=\"258685efb2b6ae123eb0e3396ae74b41\">\u63d0\u793a 1\uff1agroup+name+version \u7c7b\u4f3c\u4e8e maven \u7684 group+artifactId+version<\/p>\n\n\n\n<p id=\"2f4299e1dd5ffa13e17e92598c135195\">\u63d0\u793a 2\uff1aencoding \u89e3\u51b3\u4e1a\u52a1\u4ee3\u7801\u4e0e\u6d4b\u8bd5\u4ee3\u7801\u4e2d\u6587\u4e71\u7801\u95ee\u9898<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6211\u7684\u4ee3\u7801<\/p>\n\n\n\n<p>build.gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/7\u30011\u3001\u5e38\u89c1\u5c5e\u6027\u4ee3\u7801\n\/\/\u6307\u5b9a\u4f7f\u7528\u4ec0\u4e48\u7248\u672c\u7684JDK\u8bed\u6cd5\u7f16\u8bd1\u6e90\u4ee3\u7801,\u8ddf\u7f16\u8bd1\u73af\u5883\u6709\u5173,\u5728\u6709java\u63d2\u4ef6\u65f6\u624d\u80fd\u7528\nsourceCompatibility = JavaVersion.VERSION_1_8\n\/\/\u6307\u5b9a\u751f\u6210\u7279\u5b9a\u4e8e\u67d0\u4e2aJDK\u7248\u672c\u7684class\u6587\u4ef6:\u8ddf\u8fd0\u884c\u73af\u5883\u6709\u5173,\u5728\u6709java\u63d2\u4ef6\u65f6\u624d\u80fd\u7528\ntargetCompatibility = 1.8\n\/\/\u4e1a\u52a1\u7f16\u7801\u5b57\u7b26\u96c6,\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6e90\u7801\u89e3\u7801\u7684\u5b57\u7b26\u96c6&#91;\u7f16\u8bd1\u5668]\ncompileJava.options.encoding \"UTF-8\"\n\/\/\u6d4b\u8bd5\u7f16\u7801\u5b57\u7b26\u96c6,\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6e90\u7801\u89e3\u7801\u7684\u5b57\u7b26\u96c6&#91;\u7f16\u8bd1\u5668]\ncompileTestJava.options.encoding \"UTF-8\"\n\/\/\u7f16\u8bd1JAVA\u6587\u4ef6\u65f6\u91c7\u7528UTF-8:\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6e90\u7801\u7f16\u7801\u7684\u5b57\u7b26\u96c6\u3010\u6e90\u6587\u4ef6\u3011\ntasks.withType(JavaCompile) {\n    options.encoding = \"UTF-8\"\n}\n\/\/\u7f16\u8bd1JAVA\u6587\u4ef6\u65f6\u91c7\u7528UTF-8:\u6ce8\u610f\u8fd9\u662f\u6307\u5b9a\u6587\u6863\u7f16\u7801\u7684\u5b57\u7b26\u96c6\u3010\u6e90\u6587\u4ef6\u3011\ntasks.withType(Javadoc) {\n    options.encoding = \"UTF-8\"\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2\u3001Repositories<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>repositories {\n    \/\/gradle\u4e2d\u4f1a\u6309\u7740\u4ed3\u5e93\u914d\u7f6e\u7684\u987a\u5e8f\uff0c\u4ece\u4e0a\u5f80\u4e0b\u4f9d\u6b21\u53bb\u5bf9\u5e94\u7684\u4ed3\u5e93\u4e2d\u627e\u6240\u9700\u8981\u7684jar\u5305:\n    \/\/\u5982\u679c\u627e\u5230\uff0c\u5219\u505c\u6b62\u5411\u4e0b\u641c\u7d22\uff0c\u5982\u679c\u627e\u4e0d\u5230\uff0c\u7ee7\u7eed\u5728\u4e0b\u9762\u7684\u4ed3\u5e93\u4e2d\u67e5\u627e\n    \/\/\u6307\u5b9a\u53bb\u672c\u5730\u67d0\u4e2a\u78c1\u76d8\u76ee\u5f55\u4e2d\u67e5\u627e:\u4f7f\u7528\u672c\u5730file\u6587\u4ef6\u534f\u8bae:\u4e00\u822c\u4e0d\u7528\u8fd9\u79cd\u65b9\u5f0f\n    maven { url 'file:\/\/\/D:\/repos\/mavenrepos3.5.4'}\n    maven { url \"$rootDir\/lib\/release\" }\n    \/\/\u6307\u5b9a\u53bbmaven\u7684\u672c\u5730\u4ed3\u5e93\u67e5\u627e\n    mavenLocal()\n    \/\/\u6307\u5b9a\u53bbmaven\u7684\u79c1\u670d\u6216\u8005\u7b2c\u4e09\u65b9\u955c\u50cf\u4ed3\u5e93\u67e5\u627e\n    maven { name \"Alibaba\" ; url \"https:\/\/maven.aliyun.com\/repository\/public\" }\n    maven { name \"Bstek\" ; url \"https:\/\/nexus.bsdn.org\/content\/groups\/public\/\" }\n    \/\/\u6307\u5b9a\u53bbmaven\u7684\u8fdc\u7a0b\u4ed3\u5e93\u67e5\u627e:\u5373 https:\/\/repo.maven.apache.org\/maven2\/\n    mavenCentral()\n    \/\/\u53bbgoogle\u4ed3\u5e93\u67e5\u627egoogle()\n}<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a Gradle \u6ca1\u6709\u81ea\u5df1\u7684\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u800c\u662f\u4f7f\u7528 Maven\u3001jcenter\u3001jvy\u3001google \u8fd9\u4e9b\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6211\u7684\u4ee3\u7801<\/p>\n\n\n\n<p>build.gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>repositories {\n    \/\/mavenCentral()\n\n    \/\/7\u30012\u3001Repositories\n    \/\/gradle\u4e2d\u4f1a\u6309\u7740\u4ed3\u5e93\u914d\u7f6e\u7684\u987a\u5e8f\uff0c\u4ece\u4e0a\u5f80\u4e0b\u4f9d\u6b21\u53bb\u5bf9\u5e94\u7684\u4ed3\u5e93\u4e2d\u627e\u6240\u9700\u8981\u7684jar\u5305:\n    \/\/\u5982\u679c\u627e\u5230\uff0c\u5219\u505c\u6b62\u5411\u4e0b\u641c\u7d22\uff0c\u5982\u679c\u627e\u4e0d\u5230\uff0c\u7ee7\u7eed\u5728\u4e0b\u9762\u7684\u4ed3\u5e93\u4e2d\u67e5\u627e\n    \/\/\u6307\u5b9a\u53bb\u672c\u5730\u67d0\u4e2a\u78c1\u76d8\u76ee\u5f55\u4e2d\u67e5\u627e:\u4f7f\u7528\u672c\u5730file\u6587\u4ef6\u534f\u8bae:\u4e00\u822c\u4e0d\u7528\u8fd9\u79cd\u65b9\u5f0f\n    maven { url 'file:\/\/\/D:\/repos\/mavenrepos3.5.4'}\n    maven { url \"$rootDir\/lib\/release\" }\n    \/\/\u6307\u5b9a\u53bbmaven\u7684\u672c\u5730\u4ed3\u5e93\u67e5\u627e\n    mavenLocal()\n    \/\/\u6307\u5b9a\u53bbmaven\u7684\u79c1\u670d\u6216\u8005\u7b2c\u4e09\u65b9\u955c\u50cf\u4ed3\u5e93\u67e5\u627e\n    maven { name \"Alibaba\" ; url \"https:\/\/maven.aliyun.com\/repository\/public\" }\n    maven { name \"Bstek\" ; url \"https:\/\/nexus.bsdn.org\/content\/groups\/public\/\" }\n    \/\/\u6307\u5b9a\u53bbmaven\u7684\u8fdc\u7a0b\u4ed3\u5e93\u67e5\u627e:\u5373 https:\/\/repo.maven.apache.org\/maven2\/\n    mavenCentral()\n    \/\/\u53bbgoogle\u4ed3\u5e93\u67e5\u627egoogle()\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3\u3001Subprojects \u4e0e Allprojects<\/h3>\n\n\n\n<p id=\"3b8907a61b0ed3c5e29dabddc4f1a504\">allprojects \u662f\u5bf9\u6240\u6709 project <strong>(\u5305\u62ec Root Project + child Project [\u5f53\u524d\u5de5\u7a0b\u548c\u6240\u6709\u5b50\u5de5\u7a0b])<\/strong>\u7684\u8fdb\u884c\u7edf\u4e00\u914d\u7f6e\uff0c\u800c subprojects \u662f\u5bf9<strong>\u6240\u6709 Child Project \u7684\u8fdb\u884c\u7edf\u4e00\u914d\u7f6e<\/strong>\u3002<\/p>\n\n\n\n<p id=\"3b8907a61b0ed3c5e29dabddc4f1a504\">\u6d4b\u8bd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>allprojects {\n    tasks.create('hello') {\n        println \"project name is $project.name\"\n    }\n}\nsubprojects {\n    tasks.create('hello') {\n        println \"project name is $project.name\"\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u901a\u5e38\u5728 subprojects \u548c allprojects \u4e2d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>allprojects(){ \/\/\u672c\u8d28Project\u4e2d\u7684allprojects\u65b9\u6cd5\uff0c\u4f20\u9012\u4e00\u4e2a\u95ed\u5305\u4f5c\u4e3a\u53c2\u6570\u3002\n    apply plugin: 'java'\n    ext {\n        junitVersion = '4.10'\n        ..\n    }\n    task allTask{\n        ...\n    }\n    repositories {\n        ...\n    }\n    dependencies {\n        ...\n    }\n}\nsubprojects(){\n    \u2026\/\/\u540c\u4e0a\u9762allprojects\u4e2d\u7684\u65b9\u6cd5\u3002\n}<\/code><\/pre>\n\n\n\n<p><strong>\u62d3\u5c55 1: <\/strong> \u5982\u679c\u662f\u76f4\u63a5<strong>\u5728\u6839 project \u914d\u7f6e <\/strong>repositories \u548c dependencies \u5219<strong>\u53ea\u9488\u5bf9\u6839\u5de5\u7a0b\u6709\u6548\u3002<\/strong><\/p>\n\n\n\n<p><strong>\u62d3\u5c55:<\/strong> \u6211\u4eec\u4e5f\u53ef\u4ee5\u5728\u5bf9\u5355\u4e2a Project \u8fdb\u884c\u5355\u72ec\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>project('subject01') {\n    task subject01 {\n        doLast {\n            println 'for subject01'\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u6267\u884cgradle build \u6307\u4ee4\u5373\u53ef\u67e5\u770b\u6d4b\u8bd5\u6548\u679c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6211\u7684\u4ee3\u7801<\/p>\n\n\n\n<p>build.gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/7\u30013\u3001Subprojects \u4e0e Allprojects\nallprojects {\n    tasks.create('hello') {\n        println \"project name is $project.name\"\n    }\n}\nsubprojects {\n    tasks.create('hello') {\n        println \"project name is $project.name\"\n    }\n}\n\/\/\u6839\u636e\u540d\u5b57\u67e5\u627e\nproject('groovy-subproject01') {\n    apply plugin: 'java'\n    dependencies {\n        implementation 'org.hibernate:hibernate-core:3.6.3.Final'\n    }\n}\n\/\/\u6839\u636e\u8def\u5f84\u67e5\u627e\nproject(':groovy-subproject01') {\n    apply plugin: 'java'\n    dependencies {\n        implementation 'org.hibernate:hibernate-core:3.6.3.Final'\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4\u3001ext \u7528\u6237\u81ea\u5b9a\u4e49\u5c5e\u6027<\/h3>\n\n\n\n<p><br>Project \u548c Task \u90fd\u5141\u8bb8\u7528\u6237\u6dfb\u52a0\u989d\u5916\u7684\u81ea\u5b9a\u4e49\u5c5e\u6027\uff0c\u8981\u6dfb\u52a0\u989d\u5916\u7684\u5c5e\u6027\uff0c\u901a\u8fc7\u5e94\u7528\u6240\u5c5e\u5bf9\u8c61\u7684 ext \u5c5e\u6027\u5373\u53ef\u5b9e\u73b0\u3002\u6dfb\u52a0\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7 ext \u5c5e\u6027\u5bf9\u81ea\u5b9a\u4e49\u5c5e\u6027\u8bfb\u53d6\u548c\u8bbe\u7f6e\uff0c\u5982\u679c\u8981\u540c\u65f6\u6dfb\u52a0\u591a\u4e2a\u81ea\u5b9a\u4e49\u5c5e\u6027,\u53ef\u4ee5\u901a\u8fc7 ext \u4ee3\u7801\u5757:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u81ea\u5b9a\u4e49\u4e00\u4e2aProject\u7684\u5c5e\u6027\next.age = 18\n\/\/\u901a\u8fc7\u4ee3\u7801\u5757\u540c\u65f6\u81ea\u5b9a\u4e49\u591a\u4e2a\u5c5e\u6027\next {\n    phone = 19292883833\n    address=\"\u5317\u4eac\u5c1a\u7845\u8c37\"\n}\ntask extCustomProperty {\n    \/\/\u5728task\u4e2d\u81ea\u5b9a\u4e49\u5c5e\u6027\n    ext {\n        desc = \"\u5965\u5229\u7ed9\"\n    }\n    doLast {\n        println \"\u5e74\u9f84\u662f \uff1a${age}\"\n        println \"\u7535\u8bdd\u662f\uff1a${phone}\"\n        println \"\u5730\u5740\u662f\uff1a${address}\"\n        println \"\u5c1a\u7845\u8c37\uff1a${desc}\"\n    }\n}<\/code><\/pre>\n\n\n\n<p id=\"23a6a0b77effdb3c4076ac08537ab85c\">\u6d4b\u8bd5\uff1a\u901a\u8fc7 gradle extCustomProperty<\/p>\n\n\n\n<p id=\"9cabf2e740292548b2848e74e5e9e317\">\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5e74\u9f84\u662f\uff1a18\n\u7535\u8bdd\u662f\uff1a19292883833\n\u5730\u5740\u662f\uff1a\u5317\u4eac\u5c1a\u7845\u8c37\n\u5c1a\u7845\u8c37\uff1a\u5965\u5229\u7ed9<\/code><\/pre>\n\n\n\n<p id=\"9c883e56bd3d3e74e996ed55bebf71dd\"><strong>\u62d3\u5c55 1<\/strong>: ext \u914d\u7f6e\u7684\u662f\u7528\u6237\u81ea\u5b9a\u4e49\u5c5e\u6027\uff0c\u800c gradle.properties \u4e2d\u4e00\u822c\u5b9a\u4e49 \u7cfb\u7edf\u5c5e\u6027\u3001\u73af\u5883\u53d8\u91cf\u3001\u9879\u76ee\u5c5e\u6027\u3001JVM \u76f8\u5173\u914d\u7f6e\u4fe1\u606f\u3002\u4f8b\u5982<\/p>\n\n\n\n<p id=\"e7c869064d4199894b1699cf815893e2\">gradle.properties \u6587\u4ef6\u6848\u4f8b\uff1a\u52a0\u5feb\u6784\u5efa\u901f\u5ea6\u7684\uff0cgradle.properties \u6587\u4ef6\u4e2d\u7684\u5c5e\u6027\u4f1a\u81ea\u52a8\u5728\u9879\u76ee\u8fd0\u884c\u65f6\u52a0\u8f7d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## \u8bbe\u7f6e\u6b64\u53c2\u6570\u4e3b\u8981\u662f\u7f16\u8bd1\u4e0b\u8f7d\u5305\u4f1a\u5360\u7528\u5927\u91cf\u7684\u5185\u5b58\uff0c\u53ef\u80fd\u4f1a\u5185\u5b58\u6ea2\u51fa\norg.gradle.jvmargs=-Xms4096m -Xmx8192m\n## \u5f00\u542fgradle\u7f13\u5b58\norg.gradle.caching=true\n#\u5f00\u542f\u5e76\u884c\u7f16\u8bd1\norg.gradle.parallel=true\n#\u542f\u7528\u65b0\u7684\u5b75\u5316\u6a21\u5f0f\norg.gradle.configureondemand=true\n#\u5f00\u542f\u5b88\u62a4\u8fdb\u7a0b\norg.gradle.daemon=true<\/code><\/pre>\n\n\n\n<p>\u8be6\u7ec6\u8bf7\u53c2\u8003\uff1a<a href=\"https:\/\/docs.gradle.org\/current\/userguide\/build_environment.html#sec%3Agradle_configuration_properties\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.gradle.org\/current\/userguide\/build_environment.html#sec:gradle_configuration_properties<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6211\u7684\u4ee3\u7801<\/p>\n\n\n\n<p>build.gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/7\u30014\u3001ext \u7528\u6237\u81ea\u5b9a\u4e49\u5c5e\u6027\n\/\/\u81ea\u5b9a\u4e49\u4e00\u4e2aProject\u7684\u5c5e\u6027\next.age = 18\n\/\/\u901a\u8fc7\u4ee3\u7801\u5757\u540c\u65f6\u81ea\u5b9a\u4e49\u591a\u4e2a\u5c5e\u6027\next {\n    phone = 19292883833\n    address=\"\u5317\u4eac\u5c1a\u7845\u8c37\"\n}\ntask extCustomProperty {\n    \/\/\u5728task\u4e2d\u81ea\u5b9a\u4e49\u5c5e\u6027\n    ext {\n        desc = \"\u5965\u5229\u7ed9\"\n    }\n    doLast {\n        println \"\u5e74\u9f84\u662f \uff1a${age}\"\n        println \"\u7535\u8bdd\u662f\uff1a${phone}\"\n        println \"\u5730\u5740\u662f\uff1a${address}\"\n        println \"\u5c1a\u7845\u8c37\uff1a${desc}\"\n    }\n}<\/code><\/pre>\n\n\n\n<p>gradle.properties<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## \u8bbe\u7f6e\u6b64\u53c2\u6570\u4e3b\u8981\u662f\u7f16\u8bd1\u4e0b\u8f7d\u5305\u4f1a\u5360\u7528\u5927\u91cf\u7684\u5185\u5b58\uff0c\u53ef\u80fd\u4f1a\u5185\u5b58\u6ea2\u51fa\norg.gradle.jvmargs=-Xms4096m -Xmx8192m\n## \u5f00\u542fgradle\u7f13\u5b58\norg.gradle.caching=true\n#\u5f00\u542f\u5e76\u884c\u7f16\u8bd1\norg.gradle.parallel=true\n#\u542f\u7528\u65b0\u7684\u5b75\u5316\u6a21\u5f0f\norg.gradle.configureondemand=true\n#\u5f00\u542f\u5b88\u62a4\u8fdb\u7a0b\norg.gradle.daemon=true<\/code><\/pre>\n\n\n\n<p>groovy-subproject01 \u7684 build.gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/7\u30014\u3001ext \u7528\u6237\u81ea\u5b9a\u4e49\u5c5e\u6027\ntask extCustomProperty {\n    \/\/\u5728task\u4e2d\u81ea\u5b9a\u4e49\u5c5e\u6027\n    ext {\n        desc = \"\u5965\u5229\u7ed9\"\n    }\n    doLast {\n        println \"\u5e74\u9f84\u662f \uff1a${age}\"\n        println \"\u7535\u8bdd\u662f\uff1a${phone}\"\n        println \"\u5730\u5740\u662f\uff1a${address}\"\n        println \"\u5c1a\u7845\u8c37\uff1a${desc}\"\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5\u3001Buildscript<\/h3>\n\n\n\n<p>buildscript \u91cc\u662f gradle \u811a\u672c\u6267\u884c\u6240\u9700\u4f9d\u8d56\uff0c\u5206\u522b\u662f\u5bf9\u5e94\u7684 maven \u5e93\u548c\u63d2\u4ef6\u3002\u6848\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import org.apache.commons.codec.binary.Base64 \n\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n    dependencies {\n        classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'\n    }\n}\ntasks.register('encode') {\n    doLast {\n        def byte&#91;] encodedString = new Base64().encode('hello world\\n'.getBytes())\n        println new String(encodedString)\n    }\n}<\/code><\/pre>\n\n\n\n<p id=\"11b1d1e2ef9dd9e814d9b3b994a90491\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>buildscript{} \u5fc5\u987b\u5728 build.gradle \u6587\u4ef6\u7684\u6700\u524d\u7aef\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u591a\u9879\u76ee\u6784\u5efa\uff0c\u9879\u76ee\u7684 buildscript () \u65b9\u6cd5\u58f0\u660e\u7684\u4f9d\u8d56\u5173\u7cfb\u53ef\u7528\u4e8e\u5176\u6240\u6709\u5b50\u9879\u76ee\u7684\u6784\u5efa\u811a\u672c\u3002<\/li>\n\n\n\n<li>\u6784\u5efa\u811a\u672c\u4f9d\u8d56\u53ef\u80fd\u662f Gradle \u63d2\u4ef6\u3002\u6848\u4f8b\u5982\u4e0b\u6240\u793a\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u8001\u5f0fapply\u63d2\u4ef6\u7684\u5f15\u7528\u65b9\u5f0f,\u4f7f\u7528apply+buildscript\nbuildscript {\n    ext {\n        springBootVersion = \"2.3.3.RELEASE\"\n    }\n    repositories {\n        mavenLocal()\n        maven { url 'http:\/\/maven.aliyun.com\/nexus\/content\/groups\/public' }\n        jcenter()\n    }\n    \/\/\u6b64\u5904\u5f15\u5165\u63d2\u4ef6\n    dependencies {\n        classpath(\"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}\")\n    }\n}\napply plugin: 'java' \/\/\u6838\u5fc3\u63d2\u4ef6\uff0c\u65e0\u9700\u4e8b\u5148\u5f15\u5165\napply plugin: 'org.springframework.boot' \/\/\u793e\u533a\u63d2\u4ef6\uff0c\u9700\u8981\u4e8b\u5148\u5f15\u5165,\u624d\u80fd\u5e94\u7528\uff0c\u4e0d\u5fc5\u5199\u7248\u672c\u53f7<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>7\u3001build.gradle \u6587\u4ef6 build.gradle \u662f\u4e00\u4e2a gradle \u7684\u6784\u5efa\u811a\u672c\u6587\u4ef6,\u652f\u6301 ja [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[175],"tags":[181],"class_list":["post-4619","post","type-post","status-publish","format-standard","hentry","category-gradle-","tag-gradle"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/4619"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4619"}],"version-history":[{"count":31,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/4619\/revisions"}],"predecessor-version":[{"id":4663,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/4619\/revisions\/4663"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}