通常状况下服务器编写好服务程序 会用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