{"id":186,"date":"2022-04-18T16:43:12","date_gmt":"2022-04-18T08:43:12","guid":{"rendered":"https:\/\/www.jinhaihan.top\/WordPress\/?p=186"},"modified":"2022-04-18T16:43:14","modified_gmt":"2022-04-18T08:43:14","slug":"maven%e6%8f%92%e4%bb%b6-%e5%92%8c-maven-publish-%e6%8f%92%e4%bb%b6%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95-md","status":"publish","type":"post","link":"https:\/\/www.jinhaihan.top\/WordPress\/maven%e6%8f%92%e4%bb%b6-%e5%92%8c-maven-publish-%e6%8f%92%e4%bb%b6%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95-md\/","title":{"rendered":"maven\u63d2\u4ef6 \u548c maven-publish \u63d2\u4ef6\u4f7f\u7528\u65b9\u6cd5.md"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><blockquote>\n<p>\u622a\u53d6\u8f6c\u8f7d\u81ea\u7f51\u7edc\uff0c\u65b9\u4fbf\u8bb0\u5f55\u77e5\u8bc6\uff0c\u975e\u539f\u521b<\/p>\n<\/blockquote>\n<h1>\u4e00\u3001Maven\u63d2\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5<\/h1>\n<p>maven \u63d2\u4ef6\u662f Gradle 1.0\u7684\u65f6\u5019\u63d0\u4f9b\u7684\uff0c\u4f7f\u7528 maven \u63d2\u4ef6\uff0c\u9075\u5faa\u5982\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<h2>1 \u4f7f\u7528 maven \u63d2\u4ef6<\/h2>\n<p>\u5728 \u9700\u8981\u53d1\u5e03aar\u5305\u7684 library \u6a21\u5757\u7684 build.gradle \u6587\u4ef6\u4e2d\uff0c\u5e94\u7528 maven \u63d2\u4ef6\uff1a<\/p>\n<pre><code>apply plugin: &quot;maven&quot;\n<\/code><\/pre>\n<h2>2 \u914d\u7f6ePOM<\/h2>\n<p>\u5728 build.gradle \u6587\u4ef6\u4e2d\uff0c\u589e\u52a0\u5982\u4e0b\u7684 \u914d\u7f6e\u4fe1\u606f\uff1a<\/p>\n<pre><code>def localDefaultRepo = &quot;file:\/\/&quot; + new File(System.getProperty(&quot;user.home&quot;), &#039;.m2\/repository&#039;).absolutePath\nuploadArchives {\n    repositories.mavenDeployer {\n        \/\/ repository(url: uri(&#039;~\/.m2\/repository&#039;)) \/\/ \u6ce8\u91ca1\n        \/\/ \u914d\u7f6e\u4ed3\u5e93\u5730\u5740\n        repository(url: uri(localDefaultRepo))\n        \/\/ repository(url: uri(&#039;..\/repo&#039;))\n      \n        \/\/ \u914d\u7f6e pom \u4fe1\u606f\n        pom.groupId &quot;com.mei.http&quot;\n        pom.artifactId &quot;myhttp&quot;\n        pom.version &quot;1.0.0-SNAPSHOT&quot;\n        pom.packaging &quot;aar&quot;\n      \n      \t\/\/ pom.project {\n        \/\/    groupId &quot;com.mei.http&quot;\n        \/\/    artifactId &quot;myhttp&quot;\n        \/\/    version &quot;1.0.1-SNAPSHOT&quot;\n        \/\/    packaging &quot;aar&quot;\n        \/\/ }\n    }\n}\n<\/code><\/pre>\n<p>\u5982\u4e0a\u6240\u793a\uff0c\u6307\u5b9a \u4ed3\u5e93\u7684\u5730\u5740\uff0c\u914d\u7f6e pom \u4fe1\u606f\u3002\u8fd9\u6837\u914d\u7f6e\u5b8c\u6210\u4e4b\u540e\uff0c\u5728task \u4efb\u52a1\u5217\u8868\u4e2d\uff0c\u5c31\u53ef\u4ee5\u770b\u5230 upload\/uploadArchives \u4efb\u52a1\u3002<\/p>\n<p>\u8fd9\u91cc\u914d\u7f6e\u7684\u4ed3\u5e93\u5730\u5740\u662f\u4e00\u4e2a\u672c\u5730\u8def\u5f84\uff0c\u5373\u628a aar \u53d1\u5e03\u5230\u672c\u5730\u7684\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\u3002\u8fd9\u91cc\u7684 USER_HOME\/.m2\/repository\/ \u76ee\u5f55\uff0c\u662fGradle \u9ed8\u8ba4\u7684\u672c\u5730\u4ed3\u5e93\u5730\u5740\uff0c\u5176\u4e2d USER_HOME \u662f\u7528\u6237\u76ee\u5f55\u3002<\/p>\n<h3>2.1 \u9ed8\u8ba4\u672c\u5730\u4ed3\u5e93<\/h3>\n<p>\u5728\u6307\u5b9a \u672c\u5730\u4ed3\u5e93\u5730\u5740\u7684\u65f6\u5019\uff0c\u8e29\u4e86\u4e00\u4e2a\u5751\uff0c\u5982\u679c\u60f3\u4f7f\u7528 \u672c\u5730\u9ed8\u8ba4\u4ed3\u5e93\u5730\u5740\uff0c\u5982\uff1a<\/p>\n<pre><code>repository(url: uri(&#039;\/.m2\/repository&#039;))\nprintln &quot;path=${uri(&#039;~\/.m2\/repository&#039;)}&quot;\n<\/code><\/pre>\n<p>\u6253\u5370\u51fa\u7684\u8def\u5f84\uff1a\n<code>path=file:\/Users\/mei\/WorkSpace\/AndroidDemo\/MAarPublish\/myhttpjava\/~\/.m2\/repository\/<\/code>\n\u6267\u884c uploadArchives \u4efb\u52a1\u4e4b\u540e\uff0c\u5728 USER_HOME\/.m2\/repository\/ \u76ee\u5f55 \u4e2d\uff0c\u662f\u6ca1\u6709 aar \u6587\u4ef6\u7684,\n\u6240\u4ee5\u8fd9\u4e2a\u65f6\u5019\uff0c\u53bb\u4f7f\u7528\u7684\u8bdd\uff0c\u662f\u52a0\u8f7d\u4e0d\u5230 aar \u6587\u4ef6\u7684\u3002<\/p>\n<p>\u8fd9\u662f\u4ec0\u4e48\u539f\u56e0\u5bfc\u81f4\u7684\u5462\uff0c\u5176\u5b9e\u5c31\u662f\u8def\u5f84\u95ee\u9898\u3002<\/p>\n<p>\u5f53\u7528\u7edd\u5bf9\u8def\u5f84\u7684\u65f6\u5019\uff0c\u5373\uff1a\n<code>def localDefaultRepo = &quot;file:\/\/&quot; + new File(System.getProperty(&quot;user.home&quot;), &#039;.m2\/repository&#039;).absolutePath<\/code><\/p>\n<p>\u5f53\u4ed3\u5e93\u5730\u5740 \u7528 localDefaultRepo \u7684\u65f6\u5019\uff0c\u5728 USER_HOME\/.m2\/repository\/ \u76ee\u5f55\u5c31\u53ef\u4ee5\u770b\u5230\u53d1\u5e03\u4e4b\u540e\u7684 aar \u5305\u4e86.<\/p>\n<p>\u8fd9\u6837 aar \u5305\u5c31\u53d1\u5e03\u6210\u529f\u4e86\u3002<\/p>\n<p>\u4f7f\u7528<\/p>\n<p>\u5728 \u5de5\u7a0b\u7684 build.gradle \u6587\u4ef6\u4e2d\uff0c\u5f15\u5165\u9ed8\u8ba4\u7684\u672c\u5730\u4ed3\u5e93\uff0c\u5982\uff1a<\/p>\n<pre><code>allprojects {\n    repositories {\n        .....\n        mavenLocal() \/\/ \u4f7f\u7528\u9ed8\u8ba4\u7684\u672c\u5730\u4ed3\u5e93\n    }\n}\n<\/code><\/pre>\n<pre><code>dependencies {\n\t\t.....\n    implementation &#039;com.mei.http:myhttp:1.0.1-SNAPSHOT&#039;\n}\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u5728 app \u4e2d\u5c31\u53ef\u4ee5\u4f7f\u7528 myhttp \u4e2d\u7684\u4ee3\u7801\u4e86\u3002<\/p>\n<h3>2.2 \u81ea\u5b9a\u4e49\u672c\u5730\u4ed3\u5e93<\/h3>\n<p>\u9664\u4e86\u4f7f\u7528\u9ed8\u8ba4\u7684\u672c\u5730\u4ed3\u5e93\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u6307\u5b9a\u81ea\u5b9a\u4e49\u7684\u672c\u5730\u4ed3\u5e93\uff0c\u5373\uff1a\u81ea\u5df1\u6307\u5b9a\u4e00\u4e2a\u76ee\u5f55\uff0c\u4f5c\u4e3a\u672c\u5730\u4ed3\u5e93\uff0c\u5982\uff1a<\/p>\n<pre><code>uploadArchives {\n    repositories.mavenDeployer {\n        \/\/ \u914d\u7f6e\u4ed3\u5e93\u5730\u5740\n        repository(url: uri(&#039;..\/repo&#039;))\n      \n        \/\/ \u914d\u7f6e pom \u4fe1\u606f\n        pom.groupId &quot;com.mei.http&quot;\n        pom.artifactId &quot;myhttp&quot;\n        pom.version &quot;1.0.0-SNAPSHOT&quot;\n        pom.packaging &quot;aar&quot;\n    }\n}\n<\/code><\/pre>\n<p>\u5982\uff1a\u4e0a\u9762\u7684\u8def\u5f84\u5c31\u662f\u5728\u672c\u5de5\u7a0b\u7684\u6839\u76ee\u5f55\u4e0b\uff0c\u521b\u5efa\u4e00\u4e2a repo \u6587\u4ef6\u5939\uff0c\u7528\u4e8e\u5145\u5f53 \u672c\u5730\u4ed3\u5e93\uff0c\u6267\u884c uploadArchives \u4efb\u52a1\u4e4b\u540e\uff0c\u5728\u5de5\u7a0b\u7684\u76ee\u5f55\u4e0b\u5c31\u53ef\u4ee5\u770b\u5230 repo \u76ee\u5f55<\/p>\n<p>\u5728\u4f7f\u7528\u7684\u65f6\u5019\uff0c\u4e5f\u662f\u9700\u8981\u660e\u786e\u6307\u5b9a \u672c\u5730\u4ed3\u5e93\u7684\u8def\u5f84\uff0c\u5373\u5b58\u653e\u8be5 aar \u5305\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u4e0e\u4e0a\u9762\u7c7b\u4f3c\uff0c\u5728\u5de5\u7a0b\u7684build.gradle \u6587\u4ef6\u4e2d\uff0c\u589e\u52a0\u5982\u4e0b\u4ee3\u7801\uff0c\u6307\u660e\u672c\u5730\u4ed3\u5e93\u8def\u5f84\uff1a<\/p>\n<pre><code>allprojects {\n    repositories {\n\t\t\t\t.....\n       maven {\n           url &#039;..\/repo&#039; \/\/ \u5982\u679c\u662f\u672c\u5de5\u7a0b\u7684\u8def\u5f84\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fd9\u6837\u663e\u793a\n       }\n    }\n}\n<\/code><\/pre>\n<p>\u5982\u679c\u662f\u5176\u4ed6\u7684\u5de5\u7a0b\u60f3\u8981\u7528\u8fd9\u4e2a\u5e93\u7684\u8bdd\uff0c\u5219\u9700\u8981\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\uff0c\u5373\uff1a<\/p>\n<pre><code>allprojects {\n    repositories {\n\t\t\t\t.....\n       maven {\n           url &#039;\/Users\/mei\/WorkSpace\/AndroidDemo\/MAarPublish\/repo&#039; \n       }\n    }\n}\n<\/code><\/pre>\n<h2>3 \u4e0a\u4f20\u6e90\u7801\u548c\u6587\u6863<\/h2>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u6b65\u9aa4\uff0caar \u57fa\u672c\u4e0a\u5c31\u53d1\u5e03\u6210\u529f\u4e86\uff0c\u4f46 aar \u5305\u4e2d\u7684\u4ee3\u7801\uff0c\u90fd\u662f\u6ca1\u6709\u6ce8\u91ca\u7684\uff0c\u4e5f\u6ca1\u6709\u6e90\u7801\uff0c\u53ea\u662f\u53cd\u7f16\u8bd1\u770b\u5230\u4e00\u4e9b\u4ee3\u7801\u4fe1\u606f\uff0c\u8fd9\u79cd\u4f53\u9a8c\u5c31\u4e0d\u662f\u5f88\u597d<\/p>\n<p>\u9020\u6210\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u5c31\u662f\uff0c\u5728 \u4e0a\u4f20 aar \u6587\u4ef6\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u4e0a\u4f20\u6e90\u7801\u548c\u6587\u6863\u3002<\/p>\n<h3>3.1 \u4e0a\u4f20\u6e90\u7801<\/h3>\n<p>\u521b\u5efa\u4e00\u4e2a Task \u4efb\u52a1\uff0c\u7528\u4e8e\u4e0a\u4f20\u6e90\u4ee3\u7801\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<pre><code>task uploadSourceJar(type: Jar) {\n  \/\/ \u5b9a\u4e49\u4e00\u4e2a\u6807\u5fd7 (\u751f\u6210\u7684jar\u5305\u540e\u9762\u52a0\u4e0asources, \u5982: myhttp-1.0.2-20210927.115550-2-sources.jar)\n    classifier = &#039;sources&#039;\n    println &quot;srcDirs=${project.android.sourceSets.main.java.sourceFiles}&quot;\n  \/\/ \u6307\u5b9a\u6e90\u7801\u6587\u4ef6\u8def\u5f84\n    from project.android.sourceSets.main.java.sourceFiles\n}\n\n\/\/ \u6307\u5b9a\u53d1\u5305\u7684\u65f6\u5019\uff0c\u9700\u8981\u6267\u884c\u7684task\u4efb\u52a1\nartifacts {\n    archives uploadSourceJar\n}\n<\/code><\/pre>\n<p>\u589e\u52a0\u4e0a\u9762\u7684\u4ee3\u7801\u4e4b\u540e\uff0c\u5728\u6267\u884c uploadArchives \u4efb\u52a1\uff0c\u5c31\u4f1a\u4e0a\u4f20 \u6e90\u7801<\/p>\n<p>\u6269\u5c55\uff1a<em>artifact<\/em><\/p>\n<p>artifact\u65b9\u6cd5\u662f\u63d0\u4f9bObject\u5bf9\u8c61\uff0c\u5177\u4f53\u662f\u4ec0\u4e48\u5462\uff1f\u4e3b\u8981\u662f\u4e09\u79cd\u3002<\/p>\n<ol>\n<li>artifact &#8216;my-file-name.jar&#8217;\u5177\u4f53\u7684\u6587\u4ef6\u3002<\/li>\n<li>artifact sourceJar\u4efb\u52a1sourceJar\u8f93\u51fa\u7269\uff0c\u4f8b\u5982\u8fd9\u91cc\u662f\u5bf9\u6e90\u7801\u8fdb\u884c\u4e86\u6253\u5305\u7684Jar\u5305\u3002<\/li>\n<li>artifact source: sourceJar, classifier: &#8216;src&#8217;, extension: &#8216;zip&#8217;\u901a\u8fc7source\u3001classifier\u4ee5\u53caextension\u6784\u9020\u7684MavenArtifact\u5b9e\u4f8b\uff0c\u53c2\u6570\u5206\u522b\u5bf9\u5e94\u6e90\u6587\u4ef6\uff0c\u540d\u79f0\u7c7b\u522b(artifactId-classifier)\u4ee5\u53ca\u6269\u5c55\u540d\u79f0(.jar\/.zip\u7b49)\u3002<\/li>\n<\/ol>\n<h3>3.2 \u751f\u6210\u6587\u6863\u5e76\u4e0a\u4f20<\/h3>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u64cd\u4f5c\uff0c\u6e90\u7801\u5c31\u4e0a\u4f20\u5230maven\u4ed3\u5e93\u4e86\uff0c\u5728\u5f15\u7528 aar \u6587\u4ef6\u5230\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u770b\u5230 \u6e90\u7801\u548c\u6ce8\u91ca\u4fe1\u606f\u3002\n\u5982\u679c\u662f\u4e00\u4e2a SDK \u7684\u8bdd\uff0c\u90a3\u4e48\u4e3a\u4e86\u65b9\u4fbf\u522b\u4eba\u63a5\u5165\uff0c\u8fd8\u9700\u8981\u4e0a\u4f20\u6587\u6863\u3002<\/p>\n<pre><code>task androidJavadocs(type: Javadoc) {\n    doLast {\n        source = project.android.sourceSets.main.java.srcDirs\n        \/\/ \u9700\u8981\u751f\u6210 doc \u7684 \u4ee3\u7801\u8def\u5f84\n        classpath += project.files(project.android.getBootClasspath().join(File.pathSeparator))\n        failOnError = false \/\/ javadoc \u89e3\u6790\u9519\u8bef\u65f6task \u4e0d\u4f1a\u5f02\u5e38\u505c\u6b62\n    }\n}\n\n\/\/ \u89e3\u51b3 JavaDoc \u4e2d\u6587\u6ce8\u91ca\u751f\u6210\u5931\u8d25\u7684\u95ee\u9898\ntasks.withType(Javadoc) {\n    options.addStringOption(&#039;Xdoclint:none&#039;, &#039;-quiet&#039;)\n    options.addStringOption(&#039;encoding&#039;, &#039;UTF-8&#039;)\n    options.addStringOption(&#039;charSet&#039;, &#039;UTF-8&#039;)\n}\n\ntask androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {\n    doLast {\n        \/\/archiveFileName  The archive name. If the name has not been explicitly set\n        \/\/ , the pattern for the name is:\n        \/\/[archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]\n        \/\/ \u5b58\u6863\u540d\u79f0\u7684\u5206\u7c7b\u5668\u90e8\u5206\uff0c\u540d\u79f0\u540e\u9762\u52a0\u7684\u7c7b\u522b\u533a\u5206\u7684\u540d\u5b57.e.g. xxxx-javadoc.jar\u3002\n        classifier = &#039;javadoc&#039;\n        from androidJavadocs.destinationDir\n    }\n}\n\nartifacts {\n    \/\/ aar\u5305\u589e\u52a0\u6ce8\u91ca\n    archives androidJavadocsJar\n}\n<\/code><\/pre>\n<p>\u589e\u52a0\u5982\u4e0a\u4ee3\u7801\uff0c\u5c31\u53ef\u4ee5\u751f\u6210Java \u6587\u6863\u3002<\/p>\n<h2>4 \u4e0a\u4f20\u8fdc\u7a0b Maven \u4ed3\u5e93<\/h2>\n<p>\u8981\u60f3\u628a aar \u5305\u4e0a\u4f20\u5230\u8fdc\u7a0b\u7684 maven \u4ed3\u5e93\uff0c\u53ea\u9700\u8981\u628a\u4e0a\u9762\u7684 maven \u4ed3\u5e93\u5730\u5740\u66ff\u6362\u6210 \u8fdc\u7a0bmaven \u4ed3\u5e93\u5730\u5740\u5c31\u53ef\u4ee5\u4e86\uff0c\u9664\u6b64\u4e4b\u5916\u8fd8\u9700\u8981\u589e\u63d0\u4f9bmaven \u4ed3\u5e93\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u56e0\u4e3a\u6784\u5efa\u7684 \u79c1\u6709maven\u4ed3\u5e93\uff0c\u4e00\u822c\u90fd\u662f\u9700\u8981\u7528\u6237\u540d\u548c\u5bc6\u7801\u7684\u3002<\/p>\n<p>\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<pre><code>uploadArchives {\n    repositories.mavenDeployer {\n      \/\/ \u5047\u8bbe\u8fdc\u7a0bmaven\u4ed3\u5e93\u5730\u5740\u4e3a\uff1ahttp:\/\/10.0.192.56:8081\/repository\/core\/\n      \/\/ \u8d26\u53f7\uff1ameiTest\uff0c\u5bc6\u7801\uff1a123456\n        repository(url: &quot;http:\/\/10.0.192.56:8081\/repository\/core\/&quot;) {\n            authentication(userName: &quot;meiTest&quot;, password: &quot;123456&quot;)\n        }\n        \/\/ \u914d\u7f6e pom \u4fe1\u606f\n        pom.groupId &quot;com.mei.http&quot;\n        pom.artifactId &quot;myhttp&quot;\n        pom.version &quot;1.0.0-SNAPSHOT&quot;\n        pom.packaging &quot;aar&quot;\n    }\n}\n\n\n<\/code><\/pre>\n<p>\u5982\u4e0a\uff0c\u66ff\u6362maven\u4ed3\u5e93\u5730\u5740\uff0c\u589e\u52a0\u4ed3\u5e93\u7684\u8d26\u53f7\u548c\u5bc6\u7801\uff0c\u5c31\u53ef\u4ee5\u4e0a\u4f20\u5230\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u3002<\/p>\n<p>\u4f7f\u7528<\/p>\n<p>\u628a aar \u5305\u4e0a\u4f20\u5230 maven \u79c1\u6709\u4ed3\u5e93\u65f6\uff0c\u9700\u8981\u6821\u9a8c\u8d26\u53f7\u548c\u5bc6\u7801\uff0c\u5728\u4f7f\u7528\u7684\u7684\u65f6\u5019\uff0c\u540c\u6837\u4e5f\u8981\u6821\u9a8c\u8d26\u53f7\u548c\u5bc6\u7801\uff0c\u5982\uff1a<\/p>\n<pre><code>allprojects {\n    repositories {\n        ....\n        \/\/ \u6307\u5b9a\u79c1\u670d\u8def\u5f84\u548c\u8d26\u53f7\u5bc6\u7801\n        maven{\n            url &#039;http:\/\/10.0.192.56:8081\/repository\/core\/&#039;\n            credentials {\n                username = &quot;meiTest&quot;\n                password = &quot;123456&quot;\n            }\n        }\n    }\n}\n\n\n<\/code><\/pre>\n<h1>\u4e8c maven-publish \u63d2\u4ef6<\/h1>\n<p>\u63d2\u4ef6\u7c7b\uff1aMavenPublishPlugin<\/p>\n<p>\u5728 Gradle 6.2 \u4e4b\u540e\uff0c maven \u63d2\u4ef6\u5c31\u5f7b\u5e95\u88ab\u5e9f\u5f03\uff0c\u65e0\u6cd5\u4f7f\u7528\u4e86\uff0c\u53ea\u80fd\u4f7f\u7528 maven-publish \u63d2\u4ef6\uff0c\u56e0\u6b64 maven-publish \u63d2\u4ef6\u7684\u4f7f\u7528\u4e00\u6837\u4e5f\u8981\u638c\u63e1\u3002\u4e0b\u9762\u5c31\u6765\u770b\u770b\u5177\u4f53\u7684\u4f7f\u7528\u65b9\u5f0f\u3002<\/p>\n<h2>1 maven-publish\u63d2\u4ef6\u7684\u57fa\u672c\u4f7f\u7528<\/h2>\n<pre><code>apply plugin: &quot;maven-publish&quot;\n<\/code><\/pre>\n<p>\u914d\u7f6e\u53d1\u5e03\u4ea7\u7269\uff1a\u4f7f\u7528 maven-publish \u63d2\u4ef6\u53d1\u5e03aar \u5305\u7684\u65f6\u5019\uff0c\u57fa\u7840 \u914d\u7f6e\u4fe1\u606f \u5982\u4e0b\uff1a<\/p>\n<pre><code>publishing {\n    \/\/ \u914d\u7f6emaven \u4ed3\u5e93\n    repositories { RepositoryHandler handler-&gt;\n        handler.mavenLocal()  \/\/ \u53d1\u5e03\u5230\u9ed8\u8ba4\u7684 \u672c\u5730maven \u4ed3\u5e93 \uff0c\u8def\u5f84\uff1a USER_HOME\/.m2\/repository\/\n    }\n  \/\/ \u914d\u7f6e\u53d1\u5e03\u4ea7\u7269\n    publications {PublicationContainer publication-&gt;\n      \/\/ \u540d\u79f0\u53ef\u4ee5\u968f\u4fbf\u5b9a\u4e49\uff0c\u8fd9\u91cc\u5b9a\u4e49\u6210 maven\uff0c\u662f\u56e0\u4e3a\u6211\u7684 aar \u5305\u662f\u53d1\u5e03\u5230 maven \u4ed3\u5e93\u7684\uff0c\u6240\u4ee5\u8fd9\u91cc\u4e3a\u4e86\u89c1\u540d\u77e5\u4e49\uff0c\u5b9a\u4e49\u6210\u4e86 maven\n      \/\/ \u4efb\u52a1\u540d\u79f0\uff1amaven \n        maven(MavenPublication) {\/\/ \u5bb9\u5668\u53ef\u914d\u7f6e\u7684\u4fe1\u606f MavenPublication\n            \/\/ \u4f9d\u8d56 bundleReleaseAar \u4efb\u52a1\uff0c\u5e76\u4e0a\u4f20\u5176\u4ea7\u51fa\u7684aar\n            afterEvaluate { artifact(tasks.getByName(&quot;bundleReleaseAar&quot;)) } \/\/ \u65b9\u5f0f\u4e00\uff1a\u751f\u6210aar\u5305\n        \t  \/\/ artifact &quot;$buildDir\/outputs\/aar\/${project.name}-release.aar&quot; \/\/ \u65b9\u5f0f\u4e8c\uff1a\u6307\u5b9a\u751f\u6210\u7684aar\u8def\u5f84\n            groupId = &quot;com.mei.http&quot;\n            artifactId = &quot;myhttp&quot;\n            version = &quot;1.0.4-SNAPSHOT&quot;\n        }\n    }\n}\n\n\n<\/code><\/pre>\n<p>maven-publish \u63d2\u4ef6\u7684\u6269\u5c55\u914d\u7f6e\u7c7b\u662f\uff1aPublishingExtension\uff0c\u67e5\u770b PublishingExtension \u7c7b\u7684\u6e90\u7801\u53ef\u4ee5\u770b\u5230\uff0cpublishing \u914d\u7f6e\uff0c\u53ef\u4ee5\u914d\u7f6e\u7684\u4fe1\u606f\u6709\u4e24\u4e2a\uff1a<\/p>\n<p>repositories\uff1a\u7528\u4e8e\u914d\u7f6e maven \u4ed3\u5e93\u5730\u5740<\/p>\n<p>\u5730\u5740\u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a\uff0c\u5728\u6267\u884c publish \u4efb\u52a1\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u628a aar \u5305\u53d1\u5e03\u5230\u6240\u6709\u6307\u5b9a\u7684 maven \u4ed3\u5e93\u5730\u5740\u4e2d\u53bb\u3002<\/p>\n<pre><code>repositories { RepositoryHandler handler -&gt;\n    handler.mavenLocal()\n    handler.maven {\n        url &quot;${rootDir}\/repo&quot;\n    }\n    \/\/ \u4ed3\u5e93\u7528\u6237\u540d\u5bc6\u7801\n    \/\/ handler.maven { MavenArtifactRepository mavenArtifactRepository -&gt;\n    \/\/     \/\/ maven \u4ed3\u5e93\u5730\u5740\n    \/\/     url &#039;http:\/\/10.0.192.56:8081\/repository\/core\/&#039;\n    \/\/     \/\/ \u8bbf\u95ee\u4ed3\u5e93\u7684 \u8d26\u53f7\u548c\u5bc6\u7801\n    \/\/     credentials {\n    \/\/         username = &quot;meiTest&quot;\n    \/\/         password = &quot;123456&quot;\n    \/\/     }\n    \/\/ }\n}\n\n\n<\/code><\/pre>\n<p>publications\uff1a\u914d\u7f6e\u9700\u8981\u53d1\u5e03\u7684jar\u7684\u4fe1\u606f\uff0c\u5373\u4ea7\u7269aar\u5305\u7684\u4fe1\u606f\u3002publications \u662f\u4e00\u4e2a\u5bb9\u5668\uff0c\u7c7b\u578b\u662f PublicationContainer \uff0c\u5176\u53ef\u4ee5\u914d\u7f6e\u7684\u4fe1\u606f\u7c7b\u578b\u662f MavenPublication\u3002\u5373 \u53ef\u4ee5\u7406\u89e3\u6210 publications \u662f\u4e00\u4e2a\u5217\u8868\u96c6\u5408\uff0c\u800c\u96c6\u5408\u4e2d\u5b58\u50a8\u7684\u5bf9\u8c61\u662f MavenPublication\uff0c\u800c\u5bf9\u8c61\u7684\u540d\u79f0\u53ef\u4ee5\u7531\u81ea\u5df1\u968f\u4fbf\u5b9a\u4e49\u3002 \u6240\u4ee5 publications \u4e5f\u662f\u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a\u7684\uff0c\u5982\uff1a<\/p>\n<pre><code>publications { PublicationContainer publicationContainer -&gt;\n  \/\/ \u53d1\u5e03 snapshot \u5305\n    debug(MavenPublication) {\n        afterEvaluate { artifact(tasks.getByName(&quot;bundleReleaseAar&quot;)) }\n        groupId = &quot;com.mei.http&quot;\n        artifactId = &quot;myhttp&quot;\n        version = &quot;1.0.4-SNAPSHOT&quot;\n    }\n  \/\/ \u53d1\u5e03\u6b63\u5f0f\u5305\n    release(MavenPublication) {\n        afterEvaluate { artifact(tasks.getByName(&quot;bundleReleaseAar&quot;)) }\n        groupId = &quot;com.mei.http&quot;\n        artifactId = &quot;myhttp&quot;\n        version = &quot;1.0.4&quot;\n    }\n\n\n<\/code><\/pre>\n<p>\u6307\u5b9a\u4e0a\u4f20\u7684aar\u5305\u7684\u65b9\u5f0f\uff1a<\/p>\n<p>\u901a\u8fc7\u4f9d\u8d56\u751f\u6210 aar \u5305\u4efb\u52a1\uff0c\u5982\uff1aafterEvaluate { artifact(tasks.getByName(\u201cbundleReleaseAar\u201d)) }<\/p>\n<p>\u901a\u8fc7\u6307\u5b9a\u751f\u6210\u7684aar \u8def\u5f84\uff0c\u5982\uff1aartifact &quot;buildDir\/outputs\/aar\/buildDir\/outputs\/aar\/buildDir\/outputs\/aar\/{project.name}-release.aar&quot;<\/p>\n<p>\u53d1\u5e03aar\uff1a<\/p>\n<p>\u589e\u52a0\u4e0a\u8ff0\u914d\u7f6e\u4e4b\u540e\uff0c\u6267\u884c AS \u53f3\u4fa7\u7684 Tasks \u5217\u8868\u4e2d\u7684 publishing\/publish \u4efb\u52a1\uff0c\u5c31\u53ef\u4ee5\u53d1\u5e03 aar \u5305\u3002<\/p>\n<p>\u914d\u7f6e\u4e86\u4e24\u4e2a\u53d1\u7248\u4ea7\u54c1\uff0cdebug \u548c release\uff0c\u6267\u884c\u53d1\u5e03\u4efb\u52a1\u540e\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u9ed8\u8ba4\u7684 \u672c\u5730\u4ed3\u5e93\u4e2d\uff0c\u786e\u5b9e\u662f\u6709\u6b63\u5f0f\u5305\u548c\u6d4b\u8bd5\u5305<\/p>\n<h2>2 \u4e0a\u4f20\u6e90\u7801<\/h2>\n<p>\u5728 maven-publish \u63d2\u4ef6\u7684\u57fa\u672c\u4f7f\u7528\u4e2d\uff0c\u662f\u6ca1\u6709\u4e0a\u4f20 aar \u5305\u7684\u6e90\u7801\u7684\uff0c\u5728Android Studio \u4e2d\uff0c\u6253\u5f00\u7c7b\u67e5\u770b\u6e90\u7801\u53ef\u4ee5\u770b\u5230<\/p>\n<p>\u589e\u52a0\u4e0a\u4f20\u6e90\u7801\u7684 task\uff0c\u5982\uff1a<\/p>\n<pre><code>\/\/ 1. \u589e\u52a0\u4e0a\u4f20\u6e90\u7801\u7684task\ntask sourceJar(type: Jar) {\n    from android.sourceSets.main.java.srcDirs\n    archiveClassifier = &quot;sources&quot;\n}\n\npublishing {\n    repositories { RepositoryHandler handler -&gt;\n        handler.mavenLocal()\n    }\n    publications { PublicationContainer publicationContainer -&gt;\n        maven(MavenPublication) {\n            artifact sourceJar \/\/ \u589e\u52a0\u4e0a\u4f20\u6e90\u7801\u7684 task \n          \n            afterEvaluate { artifact(tasks.getByName(&quot;bundleReleaseAar&quot;)) }\n            groupId = &quot;com.mei.http&quot;\n            artifactId = &quot;myhttp&quot;\n            version = &quot;1.0.5-SNAPSHOT&quot;\n        }\n    }\n}\n\n\n<\/code><\/pre>\n<p>\u589e\u52a0\u4e0a\u9762\u7684\u6ce8\u91ca\u5904\u7684\u4ee3\u7801\u4e4b\u540e\uff0c\u5728\u53d1\u5e03 aar \u5305\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u8fde\u540c\u6e90\u7801\u4e00\u8d77\u4e0a\u4f20\u4e86<\/p>\n<h2>3 \u4f9d\u8d56\u4f20\u9012<\/h2>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u6b65\u9aa4\uff0c\u53d1\u5e03\u7684 aar \u5305\uff0c\u662f\u4e0d\u4f1a\u8fdb\u884c\u4f9d\u8d56\u4f20\u9012\u7684\uff0c\u5982\uff1a\u6211\u5728demo\uff1amyHttpjava \u4e2d\uff0c\u4f9d\u8d56\u4e86 OkHttp\uff0c\u5bf9 myHttpjava \u53d1\u5e03 aar \u5305\u5e76\u5f15\u7528\u4e4b\u540e\uff0c\u5728 app \u5de5\u7a0b\u4e2d\uff0c\u65e0\u6cd5\u4f7f\u7528 OkHttp \u76f8\u5173\u7684 Api\uff0c\u8fd9\u5c31\u662f\u56e0\u4e3a \u4f9d\u8d56\u6ca1\u6709\u4f20\u9012\u8fc7\u6765\u3002\u5728app \u6a21\u5757\u4e2d\uff1a<\/p>\n<pre><code>dependencies {\n\t\t\u3002\u3002\u3002\u3002\n\n    implementation &#039;com.mei.http:myhttp:1.0.4-SNAPSHOT&#039;\n}\n\n\n<\/code><\/pre>\n<p>\u65e0\u6cd5\u4f7f\u7528 OkHttp \u76f8\u5173\u7684 Api\uff0c\u4f46 myHttpjava \u81ea\u5df1\u5199\u7684\u7c7b\u53ef\u4ee5\u8c03\u7528<\/p>\n<p>\u5f53\u7136\uff0cmaven-publish \u63d2\u4ef6\uff0c\u5bf9\u4f9d\u8d56\u4f20\u9012\u4e5f\u63d0\u4f9b\u4e86\u652f\u6301\u3002\u628a library \u4e2d\u7684\u4f9d\u8d56\u4fe1\u606f\uff0c\u624b\u52a8\u7684\u6dfb\u52a0\u5230 pom \u6587\u4ef6\u4e2d\uff08\u914d\u7f6e\u4fe1\u606f\u53c2\u8003\uff1aMavenPom \u7c7b\uff09\uff0c\u5c31\u53ef\u4ee5\u5b8c\u6210\u4f9d\u8d56\u4f20\u9012\u4e86\uff0c\u5177\u4f53\u5982\u4e0b<\/p>\n<pre><code>maven(MavenPublication) {\n    \/\/ \u4f9d\u8d56 bundleReleaseAar \u4efb\u52a1\uff0c\u5e76\u4e0a\u4f20\u5176\u4ea7\u51fa\u7684aar\n    afterEvaluate { artifact(tasks.getByName(&quot;bundleReleaseAar&quot;)) }\n    artifact sourceJar\n    groupId = &quot;com.mei.http&quot;\n    artifactId = &quot;myhttp&quot;\n    version = &quot;1.0.6-SNAPSHOT&quot;\n    \/\/ pom\u6587\u4ef6\u4e2d\u58f0\u660e\u4f9d\u8d56\uff0c\u4ece\u800c\u4f20\u9012\u5230\u4f7f\u7528\u65b9\n    pom.withXml {\n        def dependenciesNode = asNode().appendNode(&#039;dependencies&#039;)\n        configurations.implementation.allDependencies.each {\n            \/\/ \u907f\u514d\u51fa\u73b0\u7a7a\u8282\u70b9\u6216 artifactId=unspecified \u7684\u8282\u70b9\n            if (it.group != null &amp;&amp; (it.name != null &amp;&amp; &quot;unspecified&quot; != it.name) &amp;&amp; it.version != null) {\n                println &quot;dependency=${it.toString()}&quot;\n                def dependencyNode = dependenciesNode.appendNode(&#039;dependency&#039;)\n                dependencyNode.appendNode(&#039;groupId&#039;, it.group)\n                dependencyNode.appendNode(&#039;artifactId&#039;, it.name)\n                dependencyNode.appendNode(&#039;version&#039;, it.version)\n                dependencyNode.appendNode(&#039;scope&#039;, &#039;implementation&#039;)\n            }\n        }\n    }\n}\n\n\n<\/code><\/pre>\n<p>\u589e\u52a0\u4e0a\u9762\u7684 pom \u6a21\u5757\uff0c\u5728 \u53d1\u5e03 aar \u5305\u7684\u65f6\u5019\uff0c\u6253\u5f00 pom \u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u4f9d\u8d56\u7684\u5e93\u7684\u58f0\u660e\u4fe1\u606f<\/p>\n<h2>4 \u7ed3\u5408 Android Gradle \u63d2\u4ef6\uff0c\u5b8c\u6210aar\u5305\u7684\u53d1\u5e03<\/h2>\n<p>\u5728\u4e0a\u9762\u7684\u6b65\u9aa4\u4e2d\uff0cpublications \u95ed\u5305\u4e2d\u7684\u6709\u4e9b\u914d\u7f6e\u8fd8\u662f\u4e0d\u591f\u4f18\u96c5\u7684\uff0c\u6bd4\u8f83\u7e41\u7410\uff0c\u5982\uff1a<\/p>\n<p>\u914d\u7f6e\u53d1\u5e03\u7684\u5185\u5bb9\uff08\u5373\u914d\u7f6e\u4e0a\u4f20\u7684 aar \u6587\u4ef6\uff09\uff0c\u662f\u901a\u8fc7\u5982\u4e0b\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<p>\u4f9d\u8d56\u751f\u6210aar\u5305\u7684Task \u4efb\u52a1\uff0c\u5982\uff1aafterEvaluate { artifact(tasks.getByName(\u201cbundleReleaseAar\u201d)) }\n\u901a\u8fc7\u6307\u5b9a\u751f\u6210\u7684aar \u6587\u4ef6\u8def\u5f84\uff0c\u5982\uff1aartifact &quot;buildDir\/outputs\/aar\/buildDir\/outputs\/aar\/buildDir\/outputs\/aar\/{project.name}-release.aar&quot;<\/p>\n<p>\u4f9d\u8d56\u4f20\u9012\uff1a\u901a\u8fc7\u624b\u52a8\u914d\u7f6e\u7684\u65b9\u5f0f\uff0c\u5373 \u4f7f\u7528 withXml \u95ed\u5305\u5f80 .pom \u6587\u4ef6\u4e2d\uff0c\u8ffd\u52a0 dependency \u4f9d\u8d56\u4fe1\u606f<\/p>\n<p>\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<pre><code>publishing {\n    \/\/ \u914d\u7f6emaven \u4ed3\u5e93\n    repositories { RepositoryHandler handler -&gt;\n        handler.mavenLocal()\n    }\n    publications { PublicationContainer publicationContainer -&gt;\n        maven(MavenPublication) {\n            \/\/ \u4f9d\u8d56 bundleReleaseAar \u4efb\u52a1\uff0c\u5e76\u4e0a\u4f20\u5176\u4ea7\u51fa\u7684aar\n            afterEvaluate { artifact(tasks.getByName(&quot;bundleReleaseAar&quot;)) }\n            \/\/ \/\/ \u4e5f\u53ef\u4ee5\u6307\u5b9a\u4e0a\u4f20\u7684AAR\u5305\uff0c\u4f46\u662f\u9700\u8981\u5148\u624b\u52a8\u751f\u6210aar\n            \/\/ artifact &quot;$buildDir\/outputs\/aar\/${project.name}-release.aar&quot;\n            artifact sourceJar\n            groupId = &quot;com.mei.http&quot;\n            artifactId = &quot;myhttp&quot;\n            version = &quot;1.0.8-SNAPSHOT&quot;\n            \/\/ pom\u6587\u4ef6\u4e2d\u58f0\u660e\u4f9d\u8d56\uff0c\u4ece\u800c\u4f20\u9012\u5230\u4f7f\u7528\u65b9\n            pom.withXml {\n                def dependenciesNode = asNode().appendNode(&#039;dependencies&#039;)\n                configurations.implementation.allDependencies.each {\n                    \/\/ \u907f\u514d\u51fa\u73b0\u7a7a\u8282\u70b9\u6216 artifactId=unspecified \u7684\u8282\u70b9\n                    if (it.group != null &amp;&amp; (it.name != null &amp;&amp; &quot;unspecified&quot; != it.name) &amp;&amp; it.version != null) {\n                        println &quot;dependency=${it.toString()}&quot;\n                        def dependencyNode = dependenciesNode.appendNode(&#039;dependency&#039;)\n                        dependencyNode.appendNode(&#039;groupId&#039;, it.group)\n                        dependencyNode.appendNode(&#039;artifactId&#039;, it.name)\n                        dependencyNode.appendNode(&#039;version&#039;, it.version)\n                        dependencyNode.appendNode(&#039;scope&#039;, &#039;implementation&#039;)\n                    }\n                }\n            }\n        }\n    }\n}\n\n\n<\/code><\/pre>\n<p>\u800c\u5728 Android \u5f00\u53d1\u4e2d\uff0c\u4e0a\u8ff0\u914d\u7f6e\u662f\u53ef\u4ee5\u7b80\u5316\u7684\u3002\u5177\u4f53\u6765\u8bf4\u5c31\u662f Android Gradle \u63d2\u4ef6\u5bf9 maven-publish \u63d2\u4ef6\u6709\u4e86\u652f\u6301\u3002<\/p>\n<p>\u4f46\u4ece Android Gradle \u63d2\u4ef6 3.6.0 \u53ca\u66f4\u9ad8\u7248\u672c\uff08\u8bf4\u7684\u662f\u8fd9\u91cc classpath &#8216;com.android.tools.build:gradle:3.6.0&#8217;\uff09\u4e4b\u540e\uff0c\u4e5f\u652f\u6301 maven-publish\u63d2\u4ef6\u4e86\uff0c\u4f7f\u914d\u7f6e\u53ef\u4ee5\u66f4\u52a0\u7b80\u6d01\u3002<\/p>\n<p>Android Gradle \u63d2\u4ef6\u4f1a\u4e3a\u5e94\u7528\u6216\u5e93\u6a21\u5757\u4e2d\u7684\u6bcf\u4e2a\u6784\u5efa\u53d8\u4f53\u5de5\u4ef6\u521b\u5efa\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u81ea\u5b9a\u4e49\u8981\u53d1\u5e03\u5230 Maven \u4ee3\u7801\u5e93\u7684\u53d1\u5e03\u5185\u5bb9<\/p>\n<p>Android \u63d2\u4ef6\u6240\u521b\u5efa\u7684\u7ec4\u4ef6\u53d6\u51b3\u4e8e\u6a21\u5757\u662f\u5426\u4f7f\u7528\u5e94\u7528\u6216\u5e93\u63d2\u4ef6\uff0c\u5982\u4e0b\u8868\u6240\u8ff0\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>module \u5e94\u8be5\u7684\u63d2\u4ef6<\/th>\n<th>\u53d1\u5e03\u5185\u5bb9\u5de5\u4ef6<\/th>\n<th>\u7ec4\u4ef6\u540d\u79f0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>com.android.library<\/td>\n<td>AAR<\/td>\n<td>components.variant<\/td>\n<\/tr>\n<tr>\n<td>com.android.application<\/td>\n<td>APK<\/td>\n<td>\u548c\u53ef\u7528\u7684 ProGuard \u6216 R8 \u6620\u5c04\u6587\u4ef6\u7684 ZIP\tcomponents.variant_apk<\/td>\n<\/tr>\n<tr>\n<td>com.android.application<\/td>\n<td>Android<\/td>\n<td>App Bundle (AAB)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u77e5\u9053\u8fd9\u4e9b\u4e4b\u540e\uff0cpublications \u7684\u914d\u7f6e\u5c31\u53d8\u5f97\u5f88\u7b80\u5355\u4e86\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<pre><code>afterEvaluate {\/\/ components.release \u53ea\u6709\u5728\u914d\u7f6e\u5b8c\u6210\u4e4b\u540e\uff0c\u624d\u80fd\u62ff\u5230\u503c\n    publishing {\n        \/\/ \u914d\u7f6emaven \u4ed3\u5e93\n        repositories { RepositoryHandler handler -&gt;\n            handler.mavenLocal()\n        }\n        publications { PublicationContainer publicationContainer -&gt;\n            maven(MavenPublication) {\n                from components.release \/\/ \u6ce8\u91ca1:\u4f7f\u7528 Android Gradle \u63d2\u4ef6\u751f\u6210\u7684\u7ec4\u4ef6\uff0c\u4f5c\u4e3a\u53d1\u5e03\u7684\u5185\u5bb9\n                artifact sourceJar \/\/ \u4e0a\u4f20\u6e90\u7801\n                groupId = &quot;com.mei.http&quot;\n                artifactId = &quot;myhttp&quot;\n                version = &quot;1.0.8-SNAPSHOT&quot;\n            }\n        }\n    }\n}\n\n\n<\/code><\/pre>\n<p>\u5982\u4e0a\u6240\u793a\uff0c\u5728\u6ce8\u91ca1\u5904\uff1a\u901a\u8fc7 from \u65b9\u6cd5\uff0c\u8bbe\u7f6e\u53d1\u5e03\u7684\u5185\u5bb9\uff0c\u800c\u5185\u5bb9\u662f Android Gradle \u63d2\u4ef6\u751f\u6210\u7684\u7ec4\u4ef6\u3002<\/p>\n<p>\u8fd9\u6837\u6307\u5b9a\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u6b63\u5e38\u7684\u4e0a\u4f20 aar \u5305\u4e86\u3002\u5e76\u4e14\u4e0d\u9700\u8981\u624b\u52a8\u7684\u6dfb\u52a0\u4f9d\u8d56\u4f20\u9012\u4fe1\u606f\uff0cAndroid Gradle \u63d2\u4ef6\u5df2\u7ecf\u5e2e\u6211\u4eec\u6dfb\u52a0\u597d\u4e86\u3002<\/p>\n<p>\u53d1\u5e03aar\u5305 \u4e4b\u540e\uff0c\u67e5\u770b .pom \u6587\u4ef6\uff0c\u4f9d\u8d56\u5e93\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u4e5f\u90fd\u662f\u6709\u7684<\/p>\n<p>\u6240\u4ee5\uff0c\u4f7f\u7528 Android Gradle \u63d2\u4ef6 \u521b\u5efa\u7684 \u7ec4\u4ef6\uff0c\u5f53\u4f5c\u53d1\u5e03\u5185\u5bb9\u7684\u65f6\u5019\uff0caar\u6587\u4ef6 \u548c \u4f9d\u8d56\u4f20\u9012\uff0c\u90fd\u5f97\u5230\u4e86\u89e3\u51b3\uff0c\u975e\u5e38\u5b8c\u7f8e\u3002<\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u7279\u522b\u6ce8\u610f\u4e00\u4e2a\u95ee\u9898<\/p>\n<p>\u5c31\u662f components \u7ec4\u4ef6\u4fe1\u606f\uff0c\u53ea\u6709\u5728 Gradle \u914d\u7f6e\u5b8c\u6210\u4e4b\u540e\uff0c\u624d\u80fd\u591f\u62ff\u5230\uff0c\u6240\u4ee5\u5728\u4f7f\u7528\u7684\u65f6\u5019\uff0c\u9700\u8981\u653e\u5728 afterEvaluate \u95ed\u5305\u5185\u3002\u8fd9\u70b9\u4e00\u5b9a\u8981\u6ce8\u610f\uff0c\u6211\u5c31\u662f\u5728\u8fd9\u4e2a\u5730\u65b9\uff0c\u88ab\u5751\u4e86\uff0c\u5f00\u59cb\u6ca1\u6709\u653e\u5728 afterEvaluate \u95ed\u5305\u5185\uff0c\u6240\u4ee5\u4e00\u76f4\u627e\u4e0d\u5230 release \u7ec4\u4ef6<\/p>\n<h1>\u56db \u53d1\u5e03 Kotlin \u9879\u76ee\u7684aar\u5305\uff0c\u6e90\u7801\u4e0a\u4f20\u95ee\u9898<\/h1>\n<p>\u5728\u914d\u7f6e\u4e0a\u4f20\u6e90\u7801\u7684 \u4efb\u52a1\u65f6\uff0c\u57fa\u672c\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre><code>task sourceJar(type: Jar) {\n    from android.sourceSets.main.java.srcDirs\n    archiveClassifier = &quot;sources&quot;\n}\n\n\n<\/code><\/pre>\n<p>\u4f46\u8fd9\u79cd\u914d\u7f6e\uff0c\u5982\u679c\u5e93\u5de5\u7a0b\u662f\u7528 Java \u5199\u7684\u8bdd\uff0c\u6e90\u7801\u53ef\u4ee5\u6b63\u5e38\u4e0a\u4f20\uff0c\u4f46\u5982\u679c\u662f Kotlin \u7f16\u5199\u7684\u5e93\uff0c\u53d1\u5e03 aar \u5305\u65f6\uff0c\u65e0\u6cd5\u67e5\u770b\u6e90\u7801\u3002<\/p>\n<p>\u901a\u8fc7 android.sourceSets.main.java.srcDirs \u6307\u5b9a\u7684\u6e90\u7801\uff0c\u53ea\u80fd\u8bc6\u522b\u5230 Java \u6587\u4ef6\uff0c\u800c kt \u6587\u4ef6\u88ab\u5ffd\u7565\u4e86\uff0c\u4f46 \u901a\u8fc7\u67e5\u770b\u5b98\u65b9\u6587\u6863\u53ef\u4ee5\u77e5\u9053\uff0cfrom \u51fd\u6570\u662f\u53ef\u4ee5\u6307\u5b9a\u6e90\u7801\u8def\u5f84\u7684\uff0c\u6240\u4ee5\u8fd9\u91cc\u76f4\u63a5\u628a from \u51fd\u6570\u7684\u53c2\u6570\u66ff\u6362\u4e3a \u6e90\u7801\u8def\u5f84\uff0c\u5373\uff1a<\/p>\n<pre><code>task sourceJar(type: Jar) {\n    from android.sourceSets.main.java.getSrcDirs() \/\/ \u6e90\u7801\u8def\u5f84\n    archiveClassifier = &quot;sources&quot;\n}\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5728 \u53d1\u5e03 aar \u5305\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u53ef\u4ee5\u6b63\u5e38\u7684\u8bbf\u95ee\u6e90\u7801\u4e86\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[8,7],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2021\/10\/4869_pc.jpg?fit=1366%2C768&ssl=1","jetpack-related-posts":[{"id":197,"url":"https:\/\/www.jinhaihan.top\/WordPress\/197\/","url_meta":{"origin":186,"position":0},"title":"gradle\u7684java\u9879\u76eeLombok\u62a5\u9519\u7684\u89e3\u51b3\u65b9\u5f0f","author":"Kim","date":"2022\u5e747\u670830\u65e5","format":false,"excerpt":"\u4e00. \u68c0\u67e5\u9879\u76ee\u914d\u7f6e \u5982\u5176\u4ed6\u535a\u5ba2\u6240\u8bf4\uff0c\u4f18\u5148\u68c0\u67e5\u9879\u76ee\u914d\u7f6e 1. \u68c0\u67e5\u9879\u76ee\u4f9d\u8d56\u662f\u5426\u6b63\u5e38\uff0c\u5305\u62ec\u6ce8\u89e3\u5904\u7406\u5668 \u5728\u2026","rel":"","context":"\u5728\u201cJava\u201d\u4e2d","block_context":{"text":"Java","link":"https:\/\/www.jinhaihan.top\/WordPress\/category\/bolg\/java\/"},"img":{"alt_text":"grey white clouds","src":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/07\/clouds-cloudporn-weather-lookup-158163.jpeg?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/07\/clouds-cloudporn-weather-lookup-158163.jpeg?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/07\/clouds-cloudporn-weather-lookup-158163.jpeg?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/07\/clouds-cloudporn-weather-lookup-158163.jpeg?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":202,"url":"https:\/\/www.jinhaihan.top\/WordPress\/maple\/","url_meta":{"origin":186,"position":1},"title":"Maple","author":"Kim","date":"2022\u5e748\u670826\u65e5","format":false,"excerpt":"\u4ee5\u4e0b\u5185\u5bb9\u6458\u81eaMaple\u4ed3\u5e93\u7684Readme Maple Series V5 \u6ce8\u610f\u4e8b\u9879 \u56e0\u4e3a\u6211\u6ca1\u6709 ma\u2026","rel":"","context":"\u5728\u201c\u535a\u5ba2\u201d\u4e2d","block_context":{"text":"\u535a\u5ba2","link":"https:\/\/www.jinhaihan.top\/WordPress\/category\/bolg\/"},"img":{"alt_text":"down angle photography of red clouds and blue sky","src":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-844297.jpeg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-844297.jpeg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-844297.jpeg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-844297.jpeg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":64,"url":"https:\/\/www.jinhaihan.top\/WordPress\/64\/","url_meta":{"origin":186,"position":2},"title":"\u865a\u5e7b4\u81ea\u5b9a\u4e49webbrowser\uff0c\u89e3\u9664\u5e27\u7387\u9501\u5b9a","author":"Kim","date":"2021\u5e744\u670830\u65e5","format":false,"excerpt":"\u6e90\u7801\u5206\u6790 Webrowser\u662f\u865a\u5e7b\u5b98\u65b9\u7684webUi\u63d2\u4ef6\uff0c\u4f46\u63d2\u4ef6\u672c\u8eab\u9ed8\u8ba4\u88ab\u9501\u4e8624FPS\uff0c\u5bfc\u81f4\u90e8\u5206\u52a8\u753b\u2026","rel":"","context":"\u5728\u201c\u865a\u5e7b4\/5\u201d\u4e2d","block_context":{"text":"\u865a\u5e7b4\/5","link":"https:\/\/www.jinhaihan.top\/WordPress\/category\/bolg\/unreal-engine\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2021\/10\/338856.jpg?fit=1200%2C750&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2021\/10\/338856.jpg?fit=1200%2C750&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2021\/10\/338856.jpg?fit=1200%2C750&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2021\/10\/338856.jpg?fit=1200%2C750&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":205,"url":"https:\/\/www.jinhaihan.top\/WordPress\/wpf%e4%b8%ad%e7%9a%84%e5%a4%9a%e8%af%ad%e8%a8%80%e6%94%af%e6%8c%81_%e5%8a%a8%e6%80%81%e5%88%87%e6%8d%a2%e8%af%ad%e8%a8%80\/","url_meta":{"origin":186,"position":3},"title":"wpf\u4e2d\u7684\u591a\u8bed\u8a00\u652f\u6301_\u52a8\u6001\u5207\u6362\u8bed\u8a00","author":"Kim","date":"2022\u5e748\u670831\u65e5","format":false,"excerpt":"\u4e3b\u6d41\u65b9\u6cd5\u53c2\u8003\u535a\u5ba2\uff1a(\u867d\u7136\u8001\u4e86\u70b9\u4f46\u662f\u6709\u7528) WPF\u5e94\u7528\u7a0b\u5e8f\u652f\u6301\u591a\u56fd\u8bed\u8a00\u89e3\u51b3\u65b9\u6848 \u4f46\u662f\u9ed8\u8ba4\u7684\u65b9\u6848\u91cc\u8bd5\u7528\u9759\u2026","rel":"","context":"\u5728\u201cWPF\u201d\u4e2d","block_context":{"text":"WPF","link":"https:\/\/www.jinhaihan.top\/WordPress\/category\/bolg\/wpf\/"},"img":{"alt_text":"pieces of paper with words","src":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-6045344.jpeg?fit=1200%2C795&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-6045344.jpeg?fit=1200%2C795&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-6045344.jpeg?fit=1200%2C795&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/08\/pexels-photo-6045344.jpeg?fit=1200%2C795&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":235,"url":"https:\/\/www.jinhaihan.top\/WordPress\/%e5%9c%a8gin%e6%a1%86%e6%9e%b6%e4%b8%ad%e8%8e%b7%e5%8f%96%e5%a4%96%e9%83%a8%e8%af%b7%e6%b1%82%e4%b8%adget%e5%92%8cpost%e7%9a%84%e5%8f%82%e6%95%b0\/","url_meta":{"origin":186,"position":4},"title":"\u5728Gin\u6846\u67b6\u4e2d\u83b7\u53d6\u5916\u90e8\u8bf7\u6c42\u4e2dGet\u548cPost\u7684\u53c2\u6570","author":"Kim","date":"2023\u5e741\u670831\u65e5","format":false,"excerpt":"\u9996\u5148\u5047\u8bbe\u5df2\u7ecf\u642d\u5efa\u597d\u6574\u4e2a\u670d\u52a1\uff0c\u5e76\u521b\u5efa\u4e86\u51e0\u4e2aAPI\u7528\u4e8e\u6d4b\u8bd5\u3002 \u5728Get\u8bf7\u6c42\u4e2d\uff0c\u5047\u8bbe\u7531\u4ee5\u4e0b\u51fd\u6570\u5904\u7406\uff0c\u5219\u83b7\u53d6\u2026","rel":"","context":"\u5728\u201cGolang\u201d\u4e2d","block_context":{"text":"Golang","link":"https:\/\/www.jinhaihan.top\/WordPress\/category\/bolg\/golang\/"},"img":{"alt_text":"Dynamic Earth - Ocean Currents","src":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2023\/01\/7402441936_5c99447ca0_b.jpg?fit=1024%2C576&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2023\/01\/7402441936_5c99447ca0_b.jpg?fit=1024%2C576&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2023\/01\/7402441936_5c99447ca0_b.jpg?fit=1024%2C576&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":232,"url":"https:\/\/www.jinhaihan.top\/WordPress\/ts%e7%9a%84%e8%af%b7%e6%b1%82%e5%b0%81%e8%a3%85\/","url_meta":{"origin":186,"position":5},"title":"TS\u7684\u8bf7\u6c42\u5c01\u88c5","author":"Kim","date":"2023\u5e741\u670831\u65e5","format":false,"excerpt":"\u9996\u5148\u5b89\u88c5axios npm install axios \u65b0\u5efarequest.ts \u8fdb\u884c\u521d\u59cb\u8bbe\u7f6e\u5e76\u8bbe\u5b9a\u2026","rel":"","context":"\u5728\u201c\u524d\u7aef\u201d\u4e2d","block_context":{"text":"\u524d\u7aef","link":"https:\/\/www.jinhaihan.top\/WordPress\/category\/bolg\/%e5%89%8d%e7%ab%af\/"},"img":{"alt_text":"purple and blue light digital wallpaper","src":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2023\/01\/pexels-photo-3780104.jpg?fit=1200%2C863&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2023\/01\/pexels-photo-3780104.jpg?fit=1200%2C863&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2023\/01\/pexels-photo-3780104.jpg?fit=1200%2C863&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2023\/01\/pexels-photo-3780104.jpg?fit=1200%2C863&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/186"}],"collection":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":1,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":187,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/186\/revisions\/187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/media\/130"}],"wp:attachment":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}