Android 发布项目到私服Nexus仓库
来源:互联网 发布:手机淘宝花呗怎么开通 编辑:程序博客网 时间:2024/05/22 12:55
部分参考自:http://blog.csdn.net/H_Zhang/article/details/51558800
发布到私服的话一般都是是使用Nexus(http://www.sonatype.org/nexus/go/),
一般公司内部会自己搭建私有Maven仓库,就把包发布到私有Maven仓库当中,以方便别人直接使用。
1.下载和配置Nexus软件
首先去官网下载Nexus软件,启动Nexus,在浏览器输入:http://localhost:8081/nexus/ 即可看到Maven仓库管理界面。
然后点击右上角进行登录,默认帐号:admin,密码:admin123。密码可以进行修改。
然后点击repositories,进入到仓库列表界面:
这里的仓库分了四种类型
1.hosted(宿主仓库):用来部署自己,第三方或者公共仓库的构件
2.proxy(代理仓库):代理远程仓库
3.virtual(虚拟仓库):默认提供了一个 Central M1虚拟仓库 用来将maven 2适配为maven 1
4.group(仓库组):统一管理多个仓库
我们可以再简历自己的hosted,也可以使用现在默认有的。一般我们发布版会在Releases下面,快照版发布在sonatype下。比如现在我需要发布在releases下面,点击releases站点:
看到上面的界面,点击config界面,设置deployment policy为Allow Redeploy。
接下来,就有很多处理方法了,有的人说点击Artrifact Upload进行上传,上传可以选择pom方式和GAV方式,都是些什么鬼,太复杂麻烦了。
还是直接使用代码上传吧!
2.配置 module build.gragle
一般我们是上传第三方库到私服中,假设现在你有一个库需要上传到私服中。
module的build.gradle的脚本代码:
apply plugin: 'com.android.library'apply plugin: 'kotlin-android'apply plugin: 'kotlin-android-extensions'apply plugin:'maven-publish'apply plugin:'maven'android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { minSdkVersion 14 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { checkReleaseBuilds false abortOnError false } packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/license.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/notice.txt' exclude 'META-INF/ASL2.0' }}dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) 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:26.+' testCompile 'junit:junit:4.12' compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.2" compile "org.jetbrains.anko:anko-common:0.8.2"}// 上传到私服Properties properties = new Properties()properties.load(project.rootProject.file('local.properties').newDataInputStream())uploadArchives { repositories { mavenDeployer { repository(url: properties.getProperty("POM_URL")) { authentication(userName: properties.getProperty("nexus.user"), password: properties.getProperty("nexus.password")) } pom.groupId = properties.getProperty("POM_GROUP_ID") pom.artifactId = properties.getProperty("POM_ATRIFACT_ID") pom.version = properties.getProperty("POM_VERSION") pom.project { licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } } } }}
可以看到,基本上都是Android Studio自动生成的代码,在头部引用了两个插件:
apply plugin:'maven-publish'apply plugin:'maven'
用于上传用的,然后就是uploadArchives 的配置了,我把对应的参数配置都藏在了local.poperties中,主要是6个参数的配置:
nexus.user=adminnexus.password=admin123POM_URL=http://localhost:8081/nexus/content/repositories/releases/POM_GROUP_ID=com.demo.libraryPOM_ATRIFACT_ID=libgifPOM_VERSION=1.0.1
nexus.user是帐号,nexus.password是密码,然后URL是你要上传到那个站点下的路由,
先看下我们这个库到时候应该是这么引用的:compile 'com.demo.library:libgif:1.0.1' 。所以:
GROUP_ID = com.demo.library
ATRIFACT_ID = libgif
VERSION = 1.0.1
这么看总该理解了吧。其他的地方按着写就可以了。
由于我的库是用Kotlin语言写的,所以在开头有两行关于kotlin的插件引用。
apply plugin:'maven-publish'apply plugin:'maven'
是用于上传需要引用的插件。
3.上传
接着就是上传了,在Android Studio的Terminal面板执行如下命令:
gradlew uploadArchives
成功后的界面:
然后我们可以在nexus的界面看到我们上传的库:
4.使用
成功后怎么使用呢?
首先在项目根目录下的build.gradle文件添加仓库url地址。
build.gradle
allprojects { repositories { jcenter() maven { url "http://localhost:8081/nexus/content/repositories/releases" } }}添加好我们的地址,然后在引用到该库的build.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:26.+' testCompile 'junit:junit:4.12' compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.2' compile 'org.jetbrains.anko:anko-common:0.8.2' compile 'com.demo.library:libgif:1.0.1'}然后运行项目就Ok了!
- Android 发布项目到私服Nexus仓库
- 内部项目发布的Nexus仓库创建
- 将项目发布到私服Nexus
- Android Studio发布项目到Maven仓库
- Android Studio发布项目到Maven仓库
- 发布本地jar到Nexus仓库
- maven 发布jar到 nexus 中央仓库
- maven发布jar包到nexus仓库
- Android Studio发布项目到Maven私有库(Nexus)
- 发布项目到Nexus私服
- 07、发布项目到nexus
- maven项目发布到nexus
- Maven项目的发布,发布到Nexus
- 发布Android studio项目到本地Maven仓库
- 通过Android Studio快速发布Library项目到maven仓库
- 通过Android Studio快速发布Library项目到maven仓库
- Android上传库到自由仓库Nexus
- maven 与 nexus 中央仓库(私服) 发布与引用
- Spring笔记二
- 使用HttpURLConnection
- #bzoj2932#【重庆市NOIP模拟赛】旅行(贪心 DP是不可以的!)
- template(name="remote" type="string" string="%msg%")
- boost库实用工具之exception
- Android 发布项目到私服Nexus仓库
- js 格式化金额
- antd源码解析(一)button控件的解析
- js定时动态增加列表
- BigDecimal加减乘除运算
- 自定义view实现多点触控
- mybatis常用jdbcType数据类型以及对应的JavaType
- [BZOJ2239]猜谜语
- lwip下TCP客户端的实现