{"id":1852,"date":"2023-03-29T22:02:56","date_gmt":"2023-03-29T14:02:56","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1852"},"modified":"2023-04-22T09:09:30","modified_gmt":"2023-04-22T01:09:30","slug":"summary-of-android-aar-package-release-to-maven-repository","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/29\/summary-of-android-aar-package-release-to-maven-repository\/","title":{"rendered":"Android aar\u5305\u53d1\u5e03\u5230maven\u4ed3\u5e93\u603b\u7ed3"},"content":{"rendered":"<h2>library module\u914d\u7f6e<\/h2>\n<p>library module\u7684<code>build.gradle<\/code>\u6587\u4ef6\uff0c\u751f\u6210aar\u5305\u542b\u6e90\u7801\u3001\u6ce8\u91ca<\/p>\n<p><!-- more --><\/p>\n<pre><code>apply plugin: &#039;maven&#039;\n\ndependencies {\n    implementation fileTree(dir: &#039;libs&#039;, include: [&#039;*.jar&#039;])\n    implementation &#039;androidx.appcompat:appcompat:1.1.0&#039;\n\n    \/\/ \u652f\u4ed8\u5b9d SDK AAR \u5305\u6240\u9700\u7684\u914d\u7f6e\n    implementation &#039;com.alipay:alipaySdk:15.7.4@aar&#039;\n}\n\nuploadArchives { \/\/\u65b0\u589e\uff0c\u56e0\u4e3aAndroid Studio gradle \u652f\u6301maven\u63d2\u4ef6\uff0c\u6240\u4ee5\u53ef\u4ee5\u6dfb\u52a0\u6b64task\n    \/\/configuration = configurations.archives\n    repositories {\n        mavenDeployer {\n            repository(url: &#039;https:\/\/repo.yezhou.me\/repository\/maven-releases\/&#039;) {\n                authentication(userName: &#039;\u8d26\u53f7&#039;, password: &#039;\u5bc6\u7801&#039;)\n            }\n            snapshotRepository(url: &#039;https:\/\/repo.yezhou.me\/repository\/maven-snapshots\/&#039;) {\n                authentication(userName: &#039;\u8d26\u53f7&#039;, password: &#039;\u5bc6\u7801&#039;)\n            }\n            pom.project {\n                \/\/version &#039;1.0.0&#039;\n                version &#039;1.0.0-SNAPSHOT&#039;\n                artifactId &#039;paySdk&#039;\n                groupId &#039;me.yezhou.pay&#039;\n                packaging &#039;aar&#039;\n                description &#039;initial version&#039; \/\/\u66f4\u65b0\u63cf\u8ff0\n\n                licenses {\n                    license {\n                        name &#039;The Apache Software License, Version 2.0&#039;\n                        url &#039;http:\/\/www.apache.org\/licenses\/LICENSE-2.0.txt&#039;\n                    }\n                }\n            }\n        }\n    }\n}\n\ntask androidJavadocs(type: Javadoc) {\n    source = android.sourceSets.main.java.srcDirs\n    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))\n}\n\ntask androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {\n    classifier = &#039;javadoc&#039;\n    from androidJavadocs.destinationDir\n}\n\ntask androidSourcesJar(type: Jar) {\n    classifier = &#039;sources&#039;\n    from android.sourceSets.main.java.srcDirs\n}\n\nartifacts {\n    \/\/aar\u5305\u589e\u52a0\u6e90\u7801\n    \/\/archives androidSourcesJar\n    \/\/aar\u5305\u589e\u52a0\u6ce8\u91ca\n    \/\/archives androidJavadocsJar\n}<\/code><\/pre>\n<p>\u6700\u540e\u5728task\u4e2d\uff0c\u70b9\u51fb<code>uploadArchives<\/code>\u4e0a\u4f20<\/p>\n<h2>aar\u5f15\u7528<\/h2>\n<p>\u95ee\u9898\uff1a\u89e3\u51b3\u8fdc\u7a0b\u4f9d\u8d56\u4f20\u9012\u5931\u6548\u95ee\u9898<\/p>\n<p>\u82e5\u8fdc\u7a0b\u4f9d\u8d56\u5931\u6548\uff0c\u5f15\u7528\u589e\u52a0<code>{transitive=true}<\/code>  \/\/\u53ef\u9009\u9879<\/p>\n<h3>\u672c\u5730\u5f15\u7528<\/h3>\n<pre><code>implementation(name: &#039;aarlibrary&#039;, ext: &#039;aar&#039;) {transitive=true}<\/code><\/pre>\n<h3>\u8fdc\u7a0b\u4f9d\u8d56<\/h3>\n<p>app moudle\u7684gradle\u4e2d\u914d\u7f6e\u5185\u90e8maven\u5e93\u8def\u5f84<\/p>\n<pre><code>repositories {\n    maven {\n        url &quot;https:\/\/repo.yezhou.me\/repository\/maven-public\/&quot;\n        credentials {\n            username = &quot;\u8d26\u53f7&quot;\n            password = &quot;\u5bc6\u7801&quot;\n        }\n    }\n}\n\nimplementation (&#039;me.yezhou.pay:paySdk:1.0.0-SNAPSHOT@aar&#039;) {transitive = true}<\/code><\/pre>\n<h3>\u62c9\u53d6\u4e0d\u5230\u6700\u65b0\u7248\u672c\u89e3\u51b3<\/h3>\n<p>\u5728 Gradle \u5f15\u7528<code>SNAPSHOT<\/code>\u5e93\u7248\u672c\u65f6\uff0c\u82e5\u9047\u5230\u5df2\u7ecf\u4e0a\u4f20\u6700\u65b0\u7248\u672c\uff0c\u4f46\u662f\u597d\u50cf\u6ca1\u6709\u4f5c\u7528\u65f6\u3002\u8bf7\u5148\u5230\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6e05\u7406\u4e00\u4e0bGradle\u7684\u7f13\u5b58\uff0c\u518d\u4e14\u8bd5\u8bd5\uff1a<\/p>\n<pre><code>\/\/Windows\ngradlew build --refresh-dependencies\n\n\/\/Mac\n.\/gradlew build --refresh-dependencies<\/code><\/pre>\n<h2>\u914d\u7f6e\u5c01\u88c5<\/h2>\n<p>\u5728 Library Moudle \u4e2d\u521b\u5efa\u4e00\u4e2a<code>gradle.properties<\/code>\u6587\u4ef6\uff0c\u8bb0\u5f55 Nexus \u7684\u79c1\u670d\u7684\u7528\u6237\u540d\u79f0\u548c\u5bc6\u7801\uff0c\u8981\u4e0a\u4f20\u7684\u76ee\u6807\u4ed3\u5e93\u5730\u5740\uff0c\u4ee5\u53ca\u4e0a\u4f20\u6784\u4ef6\u7684\u4fe1\u606f\u3002<\/p>\n<pre><code>\/\/\u4e0a\u4f20\u6784\u4ef6\u7684\u4fe1\u606f\nGROUP_ID=me.yezhou.pay\nARTIFACT_ID=paySdk\nVERSION=1.0.0\n#VERSION=1.0.0-SNAPSHOT  \u5feb\u7167\u5e93\n#VERSION=1.0.0\u00a0 Release\u5e93\n\n\/\/\u4e0a\u4f20\u7684\u76ee\u6807\u4ed3\u5e93\u5730\u5740\nSNAPSHOT_REPOSITORY_URL=http:\/\/localhost:8081\/repository\/maven-snapshots\/\nRELEASE_REPOSITORY_URL=http:\/\/localhost:8081\/repository\/maven-releases\/\n\n\/\/Nexus \u7684\u79c1\u670d\u7684\u7528\u6237\u540d\u79f0\u548c\u5bc6\u7801\nNEXUS_USERNAME=admin\nNEXUS_PASSWORD=admin123<\/code><\/pre>\n<p>\u521b\u5efa<code>nexus_publish.gradle<\/code>\u6587\u4ef6\uff0c\u7528\u6765\u751f\u6210<code>sources.jar<\/code>\u6e90\u7801\u5305\u548c<code>javadoc.jar<\/code>\u65b9\u6cd5\u6587\u6863\u548c\u521b\u5efa\u4e0a\u4f20\u7684 Gradle Task<\/p>\n<pre><code>apply plugin: &#039;maven&#039;\n\n\/\/ \u5224\u65ad\u7248\u672c\u662fRelease or Snapshots\ndef isReleaseBuild() {\n    return VERSION.toUpperCase().contains(&quot;SNAPSHOT&quot;) == false\n}\ndef getRepositoryUsername() {\n    return hasProperty(&#039;NEXUS_USERNAME&#039;) ? NEXUS_USERNAME : &quot;&quot;\n}\ndef getRepositoryPassword() {\n    return hasProperty(&#039;NEXUS_PASSWORD&#039;) ? NEXUS_PASSWORD : &quot;&quot;\n}\ndef getRepositoryUrl() {\n    return isReleaseBuild() ? RELEASE_REPOSITORY_URL : SNAPSHOT_REPOSITORY_URL\n}\nafterEvaluate { project -&gt;\n    uploadArchives {\n        repositories {\n            mavenDeployer {\n                pom.groupId = GROUP_ID\n                pom.artifactId = ARTIFACT_ID\n                pom.version = VERSION\n                repository(url: getRepositoryUrl()) {\n                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())\n                }\n            }\n        }\n    }\n    task androidJavadocs(type: Javadoc) {\n        source = android.sourceSets.main.java.srcDirs\n        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))\n    }\n    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {\n        classifier = &#039;javadoc&#039;\n        from androidJavadocs.destinationDir\n    }\n    task androidSourcesJar(type: Jar) {\n        classifier = &#039;sources&#039;\n        from android.sourceSets.main.java.sourceFiles\n    }\n\n   \/\/\u89e3\u51b3 JavaDoc \u4e2d\u6587\u6ce8\u91ca\u751f\u6210\u5931\u8d25\u7684\u95ee\u9898\n    tasks.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    artifacts {\n        archives androidSourcesJar\n        archives androidJavadocsJar\n    }\n}<\/code><\/pre>\n<p>\u7136\u540e\u5728 Library Moudle \u7684<code>build.gradle<\/code>\u4e2d\u5f15\u7528<code>nexus_publish.gradle<\/code><\/p>\n<pre><code>apply from: &#039;nexus_publish.gradle&#039;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>library module\u914d\u7f6e library module\u7684build.gradle\u6587\u4ef6\uff0c\u751f\u6210aar\u5305\u542b\u6e90 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[202],"tags":[307,475],"class_list":["post-1852","post","type-post","status-publish","format-standard","hentry","category-android-build","tag-aar","tag-nexus"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1852"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1852\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}