[Android]上傳到多個Maven倉庫的Gradle外掛程式RapidMavenPushPlugin

來源:互聯網
上載者:User

標籤:mon   module   注入   ace   dev   enc   push   conf   require   

部落格搬遷至https://blog.wangjiegulu.com

RSS訂閱:https://blog.wangjiegulu.com/feed.xml

RapidMavenPushPlugin

用於上傳你的 library 庫到多個 Maven 倉庫的 Gradle 外掛程式。

Github: https://github.com/wangjiegulu/RapidMavenPushPlugin

1. 怎麼使用1.1 添加依賴

在你項目根目錄的 build.gradle 檔案中增加 RapidMavenPushPlugin 依賴:

檢查最新版本

buildscript {    repositories {        google()        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:3.0.1'        classpath('com.github.wangjiegulu:rapidmavenpush:x.x.x') {            exclude group: 'com.android.tools.build', module: 'gradle'        }    }}
1.2 建立 properties files

現在你有3個 Maven 倉庫(maven types),所以需要建立3個 maven properties archive 檔案和1個通用的 archive properties 檔案(properties 檔案的名字和位置可以是任意的):

  • maven_local.properties: 上傳 archives 到本地的 maven 倉庫, 預設在你電腦的 ~/.m2/repository
  • maven_company.properties: 上傳 archives 到你公司的 maven 倉庫,他部署在你公司的伺服器上面。
  • maven_central.properties: 上傳 archives 到 maven 中央庫。
  • common.properties: 上面3個 maven 倉庫的通用 properties。

NOTE: 當 project.afterEvaluate 時, 所有 properties 都會被自動注入到 project.ext中,所以在那之後你可以以諸如 $POM_ARCHIVE_ID 的方式來使用它們。

1.2.1 maven_common.properties
# project infoPOM_ARCHIVE_GROUP=com.github.wangjiegulu#POM_ARCHIVE_VERSION_NAME=0.0.1-SNAPSHOT (command typed)# aar or jarPOM_PACKAGING=aarPOM_DESC=test-mavenpush-pluginPOM_URL=https://github.com/wangjieguluPOM_SCM_URL=scm:[email protected]:wangjieguluPOM_SCM_CONNECTION=scm:[email protected]:wangjiegulu[email protected]:wangjieguluPOM_LICENCE_NAME=The Apache Software License, Version 2.0POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txtPOM_LICENCE_DIST=wangjiePOM_DEVELOPER_ID=wangjiePOM_DEVELOPER_NAME=Wang Jie[email protected]
1.2.2 maven_local.properties
# maven repositoryPOM_REPOSITORY_URL=/Users/wangjie/.m2/repositoryPOM_REPOSITORY_URL_SNAPSHOT=/Users/wangjie/.m2/repositoryPOM_SIGN=false# project infoPOM_ARCHIVE_ID=mavenpush-plugin-depmodule-local
1.2.3 maven_central.properties
POM_OSSRH_USERNAME=usernamePOM_OSSRH_PASSWORD=password# maven repositoryPOM_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2/POM_REPOSITORY_URL_SNAPSHOT=https://oss.sonatype.org/content/repositories/snapshots/POM_SIGN=true# Already configure in ~/.gradle/gradle.properties#signing.keyId=#signing.password=#signing.secretKeyRingFile=# project infoPOM_ARCHIVE_ID=mavenpush-plugin-depmodule
1.3 應用 Plugin & properties

在你 library 的 build.gradle 檔案中, 你需要以如下方式來 apply RapidMavenPushPlugin 外掛程式:

apply plugin: 'com.github.wangjiegulu.plg.rapidmavenpush'rapidMavenPush {    // 如果是 true,會在編譯時間期列印被注入的 properties    printProperties = true    // 如果是 true,在注入 properties 發生錯誤時會終止編譯    abortOnError = false    // 是否禁用 Rapid Maven Push Plugin    disable = false    // 如果 `POM_MAVEN_TYPE` 沒有被設定,則使用預設的 maven type。    defaultMavenType = 'local'    mavens {        maven {            mavenType = 'local'            propertyFiles = [                    file("mavenupload/maven_common.properties"),                    file("mavenupload/maven_local.properties")            ]            // Property Inject Mode: If the properties is already set, replace it or skip            // property 注入模式:如果 properties 已經被設定過,則替換還是跳過            propertyInjectMode = 'replace'        }        maven {            mavenType = 'company'            propertyFiles = [                    file("mavenupload/maven_common.properties"),                    file("mavenupload/maven_company.properties")            ]            propertyInjectMode = 'replace'        }        maven {            mavenType = 'central'            propertyFiles = [                    file("mavenupload/maven_common.properties"),                    file("mavenupload/maven_central.properties")            ]            propertyInjectMode = 'replace'        }    }}
1.4 上傳 Archives

在編譯之後,rapid maven push plugin 自動建立了一個名為 rapidUploadArchives 的 task。

執行這個 task !

上傳 archives 到本地倉庫:

./gradlew clean :depmodule:rapidUploadArchives -PPOM_MAVEN_TYPE=local

上傳 archives to 到中央庫:

./gradlew clean :depmodule:rapidUploadArchives -PPOM_MAVEN_TYPE=central

NOTE: 如果你沒有在 build.gradle 使用 ext.POM_MAVEN_TYPE=xxx 的方式進行設定的話,POM_MAVEN_TYPE 參數是必要的。

1.5 支援的 parameters & properties
// maven type, 只能通過在 `build.gradle` 設定 `ext.POM_MAVEN_TYPE=xxx` 或者在命令列中設定 `-PPOM_MAVEN_TYPE=xxx` 或者在 `gradle.properties` 中設定 `PPOM_MAVEN_TYPE=xxx`POM_MAVEN_TYPE// maven repository parametersPOM_REPOSITORY_URLPOM_REPOSITORY_URL_SNAPSHOTPOM_OSSRH_USERNAMEPOM_OSSRH_PASSWORD// sign parametersPOM_SIGNsigning.keyIdsigning.passwordsigning.secretKeyRingFile// archive parametersPOM_ARCHIVE_GROUPPOM_ARCHIVE_IDPOM_ARCHIVE_VERSION_NAMEPOM_PACKAGINGPOM_DESCPOM_URLPOM_SCM_URLPOM_SCM_CONNECTIONPOM_SCM_DEV_CONNECTIONPOM_LICENCE_NAMEPOM_LICENCE_URLPOM_LICENCE_DISTPOM_DEVELOPER_IDPOM_DEVELOPER_NAMEPOM_DEVELOPER_EMAIL
License
Copyright 2018 Wang JieLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

[Android]上傳到多個Maven倉庫的Gradle外掛程式RapidMavenPushPlugin

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.