通常狀況下服務器編寫好服務程序 會用Maven打成JAR包,放在Maven倉庫裏管理,咱們在用的時候直接引用就能夠,android
那麼如何在Gradle項目中使用本地的 或者遠程的Maven倉庫呢 當Maven倉庫裏的JAR包有更新時 咱們能夠用Gradle編譯時直接從Maven倉庫裏下載(針對公司本地的服務器Jar包更新,每次服務器更新Jar包不用手動更新直接鏈接Maven倉庫加載對應的類庫)spring
一、在咱們的工程的目錄下的gradle文件配置服務器
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories {//默認加載所需類庫都會去jcenter中加載 若是沒有找對對應的類庫則會去咱們配置的Maven倉庫中查找 jcenter() maven{//配置Maven倉庫的地址 url "http://repo.springsource.org/libs-milestone-local" } } } task clean(type: Delete) { delete rootProject.buildDir }
咱們能夠看見 紅色的jcenter() 在咱們app的目錄下的build.gradle文件裏 咱們常常會看到 compile 'com.google.gson:gson:2.2.4'之類的寫法 app
com.google.gson:gson:2.2.4這個庫其實在jcenter裏邊有 若是加載一個類庫jcenter中沒有 那麼就會去咱們配置的Maven倉庫中查找maven
配置好上面的文件後 咱們須要在 app目錄下的build.gradle中去引用所須要的類庫gradle
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:support-v4:25.1.1' testCompile 'junit:junit:4.12' compile 'com.gopivotal.manager:common:1.2.1.RELEASE' }
紅色部分就是 咱們引用的操做 你會發現咱們引用的庫 有三部分 分別用:隔開ui
GroupId: com.gopivotal.manager
ArtifactId: common
version:1.2.1.RELEASE
這三個其實就組成了Maven倉庫裏對應庫的路徑
執行一次build以後就能夠使用對應的類了
給你們幾個經常使用的Maven地址 能夠嘗試一下
https://repo1.maven.org/maven2/
https://repository.jboss.org/maven2/
https://repository.sonatype.org/content/groups/public/
http://maven.aliyun.com/nexus/content/groups/public
http://repo.springsource.org/libs-milestone-local