Maven从入门到提高(二)
来源:互联网 发布:写代码的软件 编辑:程序博客网 时间:2024/06/09 08:46
发布Android studio项目到本地Maven仓库
说明
Android studio 可以在build.gradle文件中添加如下的格式来引用第三方库,如:
compile 'com.dragonpass.sundy.modulefounder:limousine:1.0.3'
该格式由三个部分组成,你可以在pom 文件中找到。
<?xml version="1.0" encoding="UTF-8"?><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>com.dragonpass.sundy.modulefounder</groupId> <artifactId>limousine</artifactId> <version>1.0.3</version> <packaging>aar</packaging> <dependencies> <dependency> <groupId>com.android.support</groupId> <artifactId>appcompat-v7</artifactId> <version>24.2.1</version> <scope>compile</scope> </dependency> </dependencies></project>
groupId:唯一标识符
artifactId:类似于项目名称
version:版本号
pom 文件可以在你Maven 仓库对一个项目里的文件目录下找到,如:
现在我们自己来创建一个第三方Library 放到我们的本机的Maven 仓库
第一步
新建一个Android 项目。在gradle.properties 文件添加以下信息
#包信息GROUP_ID=com.dragonpass.sundy.modulefounder# Licence信息PROJ_LICENCE_NAME=The Apache Software License, Version 2.0PROJ_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txtPROJ_LICENCE_DEST=repo
GROUP_ID:就是刚才的groupId
Licence 信息是固定的
第二步
新建一个Library, 我命名为limousine(这个是我要从一个项目分出来的一个模块)
在Library 的根目录下新建gradle.properties 文件,添加
#包信息ARTIFACTID=limousineLIBRARY_VERSION=1.0.0#Mac下地址:LOCAL_REPO_URL=file:///Users/sundy/Documents/MavenRepo
ARTIFACTID:开始说的artifactId
LIBRARY_VERSION: 版本号
LOCAL_REPO_URL: 本地仓库的地址: file://+本地路径
第三步
在Library 也就是刚才创建的limousine下的build.gradle文件中添加
apply plugin: 'maven'uploadArchives{ repositories.mavenDeployer{ repository(url:LOCAL_REPO_URL) pom.groupId = GROUP_ID pom.artifactId = ARTIFACTID pom.version = LIBRARY_VERSION }}
第四步
最后在项目路径下执行gradlew 命名:
./gradlew -p <Library name> clean build uploadArchives --info
我自己的是:
./gradlew -p limousine clean build uploadArchives --info
如果自己懒得打字,可以用Android Studio 自带的Gradle 插件工具,只要点击一下就好了,找到该位置,如
执行结束没有报错一般会在你的Maven 仓库路径下有刚刚发布好的Library了。
LOCAL_REPO_URL=file:///Users/sundy/Documents/MavenRepo
第五步
引用,先在项目最外层的build.gradle 文件中添加Maven 库路径
// 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.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { jcenter() maven { url 'file:///Users/sundy/Documents/MavenRepo' } }}task clean(type: Delete) { delete rootProject.buildDir}
就是:
maven { url 'file:///Users/sundy/Documents/MavenRepo' }
然后在需要引用这个库的项目的build.gradle中添加:
compile 'com.dragonpass.sundy.modulefounder:limousine:1.0.3'
然后就可以了。
项目GitHub 地址:https://github.com/xuxian361/MavenDemo-LocalRepo
- Maven从入门到提高(二)
- Maven从入门到提高(一)
- Maven从入门到提高(三)
- Maven从入门到提高(四)
- Maven从入门到入门
- ANT 从入门到提高
- ANT从入门到提高
- java从入门到JUnit到maven
- 堆栈溢出从入门到提高
- Spring学习从入门到提高
- 堆栈溢出从入门到提高
- 堆栈溢出从入门到提高
- 黑马程序员 SQL从入门到提高
- MongoDB从入门到提高【第二集】
- MongoDB从入门到提高【第一集】
- 堆栈溢出从入门到提高
- Fusioncharts工具从入门到提高
- 快速排序算法从入门到提高
- 计算机科学基础知识(四): 动态库和位置无关代码
- iOS宏和__attribute__
- JVM虚拟机的理解
- PHP流程控制
- Linux netstat命令详解
- Maven从入门到提高(二)
- MyEclipse10 JNDI的使用及配置
- mysql差异备份——增量备份区别
- Shell常用命令整理
- 12BET Malaysia 30% Birthday Bonus
- 蓝桥杯
- Linux系统下安装rz/sz命令及使用说明
- spaly-洛谷P2286 [HNOI2004]宠物收养场
- AngularJS中的依赖注入 二