利用Github创建maven仓库
利用Github托管功能创建代码maven仓库。
环境
- Github账号。
- Github上托管maven仓库的工程AoriseMaven(命名可以随意)。
- 本地编译生成pom文件的源码工程。
远程仓库
- 利用Github创建用于托管pom文件的空仓库AoriseMaven.
- 克隆空仓库到本地:’D:\Github\AoriseMaven’.
源码工程
- 在需要打包托管到maven仓库的module工程的’build.gradle’文件添加如下配置:
  apply plugin: 'com.android.library'
  android {
    ...
  }
  dependencies {
    ...
  }
  apply plugin: 'maven'
  apply from: '../config/maven-common.gradle'
- 在工程根目录的’gradle.properties’文件添加编译生成的pom文件的output路径:
  aar.deployPathCommon=D\:\\GitHub\\AoriseMaven
- 在工程根目录创建’config/maven-common.gradle’文件:
  ext {
      PUBLISH_GROUP_ID = 'cn.aorise'
      PUBLISH_ARTIFACT_ID = 'common'
      PUBLISH_VERSION = android.defaultConfig.versionName
  }
  uploadArchives {
      repositories.mavenDeployer {
          def deployPath = file(getProperty('aar.deployPathCommon'))
          repository(url: "file://${deployPath.absolutePath}")
          // def deployPath = file('E://maven-local/')    // 绝对路径可以
          // def deployPath = file('../maven-snapshots')  // 相对路径可以
          pom.project {
              groupId project.PUBLISH_GROUP_ID
              artifactId project.PUBLISH_ARTIFACT_ID
              version project.PUBLISH_VERSION
          }
      }
  }
- 在需要打包托管到maven仓库的module工程根目录执行gradle命令:
  gradle uploadArchives
上传POM文件
- Gradle命令成功后会在配置的output路径(D:\Github\AoriseMaven)生成POM文件,文件结构如下:
   
- Push文件到Github远程仓库。
- Github的maven远程仓库的地址如下:
    https://raw.githubusercontent.com/github的username/仓库名/master 
应用Maven仓库
- 在调用maven仓库的AS工程文件根目录的’build.gradle’文件添加如下配置:
    allprojects { repositories { ... // aorise commonLib 远程仓库地址 // maven { url "http://10.16.3.12:8080/tools/maven-snapshots/" } maven { url "https://raw.githubusercontent.com/aorise-org/maven-snapshots/master" } // maven { url "file://E://maven-local/" } } }
- 在调用maven仓库的module的’build.gradle’文件添加如下配置:
    dependencies { ... compile 'cn.aorise:common:1.0.3' }
以上步骤全部完成后,module模块就可以调用maven远程仓库里面的内容,包括函数、资源文件、assets里面的文件等。

