博客搬遷至https://blog.wangjiegulu.comandroid
RSS訂閱:https://blog.wangjiegulu.com/feed.xmlgit
用於上傳你的 library 庫到多個 Maven 倉庫的 Gradle 插件。github
Github: https://github.com/wangjiegulu/RapidMavenPushPluginexpress
在你項目根目錄的 build.gradle
文件中增長 RapidMavenPushPlugin
依賴:apache
檢查最新版本api
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' } } }
如今你有3個 Maven 倉庫(maven type
s),因此須要建立3個 maven properties archive 文件和1個通用的 archive properties 文件(properties 文件的名字和位置能夠是任意的):服務器
~/.m2/repository
。NOTE: 當
project.afterEvaluate
時, 全部 properties 都會被自動注入到project.ext
中,因此在那以後你能夠以諸如$POM_ARCHIVE_ID
的方式來使用它們。app
# project info POM_ARCHIVE_GROUP=com.github.wangjiegulu #POM_ARCHIVE_VERSION_NAME=0.0.1-SNAPSHOT (command typed) # aar or jar POM_PACKAGING=aar POM_DESC=test-mavenpush-plugin POM_URL=https://github.com/wangjiegulu POM_SCM_URL=scm:git@github.com:wangjiegulu POM_SCM_CONNECTION=scm:git@github.com:wangjiegulu POM_SCM_DEV_CONNECTION=git@github.com:wangjiegulu POM_LICENCE_NAME=The Apache Software License, Version 2.0 POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=wangjie POM_DEVELOPER_ID=wangjie POM_DEVELOPER_NAME=Wang Jie POM_DEVELOPER_EMAIL=tiantian.china.2@gmail.com
# maven repository POM_REPOSITORY_URL=/Users/wangjie/.m2/repository POM_REPOSITORY_URL_SNAPSHOT=/Users/wangjie/.m2/repository POM_SIGN=false # project info POM_ARCHIVE_ID=mavenpush-plugin-depmodule-local
POM_OSSRH_USERNAME=username POM_OSSRH_PASSWORD=password # maven repository POM_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 info POM_ARCHIVE_ID=mavenpush-plugin-depmodule
在你 library 的 build.gradle
文件中, 你須要以以下方式來 apply RapidMavenPushPlugin 插件:less
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' } } }
在編譯以後,rapid maven push plugin 自動建立了一個名爲 rapidUploadArchives
的 task。maven
執行這個 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
參數是必要的。
// maven type, 只能經過在 `build.gradle` 設置 `ext.POM_MAVEN_TYPE=xxx` 或者在命令行中設置 `-PPOM_MAVEN_TYPE=xxx` 或者在 `gradle.properties` 中設置 `PPOM_MAVEN_TYPE=xxx` POM_MAVEN_TYPE // maven repository parameters POM_REPOSITORY_URL POM_REPOSITORY_URL_SNAPSHOT POM_OSSRH_USERNAME POM_OSSRH_PASSWORD // sign parameters POM_SIGN signing.keyId signing.password signing.secretKeyRingFile // archive parameters POM_ARCHIVE_GROUP POM_ARCHIVE_ID POM_ARCHIVE_VERSION_NAME POM_PACKAGING POM_DESC POM_URL POM_SCM_URL POM_SCM_CONNECTION POM_SCM_DEV_CONNECTION POM_LICENCE_NAME POM_LICENCE_URL POM_LICENCE_DIST POM_DEVELOPER_ID POM_DEVELOPER_NAME POM_DEVELOPER_EMAIL
Copyright 2018 Wang Jie Licensed 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.0 Unless required by applicable law or agreed to in writing, software distributed 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 and limitations under the License.