您的位置:首页 > 移动开发 > Android开发

android gradle dependencies

2015-11-30 14:58 573 查看
dependencies compile:依赖某个包。例如:
compile 'com.android.support:appcompat-v7:22.2.1'
那么,它是存在哪里呢?
repositories {
mavenCentral()
}
maven中央库:可以自己构建,也可以使用第三方的。
自己构建为例:
用maven管理项目时,如果某人加入了maven中心库无法下载到的依赖包,则其他人同步代码后整个项目会报错,我们可以配置一个自己的maven库来解决这个问题。http://maven.apache.org/repository-management.html推荐了几个可用于配置maven库的软件,比如Apache Archiva,Artifactory。本文将选择nexus来配置一个maven库。 操作系统为64位Centos 6.31.从http://www.sonatype.org/nexus/go下载nexus-2.3.0-04.zip或者nexus-2.3.0-04-bundle.tar.gznexus-2.3.0-04.zip解压之后放入Tomcat等web容器中即可,下面介绍nexus-2.3.0-04-bundle.tar.gz配置。2.下面命令最好不要用root帐号操作,因为nexus不推荐用root帐号启动,而目录拥有者和启动帐号不一致会有其他问题产生3.解压下载的文件到安装目录,比如:/usr/local,tar -zxf nexus-2.3.0-04-bundle.tar.gz4.进入解压目录,chmod -R a+x bin5.启动nexus,bin/jsw/linux-x86-64/nexus start6.启动nexus的帐号对sonatype-work(和nexus-2.3.0-04目录同级)目录要有读写权限7.在浏览器输入http://ip:8081/nexus,在页面右上角有登录连接,默认账户是admin,密码admin123(注意防火墙是否允许访问8081接口)8.点击Repositories将会看到如下界面,其中红色框的三个库是我们配置自己maven的主要原因
9.首先上传一个第三方的包(淘宝sdk),按下图提示填入后upload即可
10.然后我们把自己的项目安装到这个库中,首先需要配置settings.xmlXml代码

<server>
<id>inexus</id>
<username>admin</username>
<password>admin123</password>
</server>
然后在项目的pom.xml文件中加入如下xml片段Xml代码

<distributionManagement>
<repository>
<id>inexus</id>
<name>Release</name>
<url>http://192.168.202.129:8081/nexus/content/repositories/releases/</url> </repository>
<snapshotRepository>
<id>inexus</id>
<name>Snapshots</name>
<url>http://192.168.202.129:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
然后使用mvn:deploy命令即可将项目安装到maven库中 11.从自己的maven库获取依赖包,配置settings.xml文件,其中profile片段可以放到项目的pom.xml中Xml代码

<profile>
<id>nexus</id>
<repositories>
<repository>
<id>inexus</id>
<url>http://192.168.202.129:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots> </repository>
</repositories>
</profile>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
12.当有web的项目时, 如果maven-war-plugin过低时发布会报错Xml代码

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: