使用Artifactory搭建私有Maven仓库
来源:互联网 发布:吴京票房号召力知乎 编辑:程序博客网 时间:2024/05/19 05:29
在涉及到模块化开发过程中,我们想要将公开或公用组件 aar/jar 上传至Maven Center or JCenter 仓库中心(将Android项目开源到JCenter两种方式),以便于持续集成。但是对于有些组件我们不想对外公开这时候就需要我们搭建一个本地私有仓库了。
使用Artifactory简单搭建本地仓库
1. 下载并解压 Artifactory
由此可见 artfactory
使用的是自带的tomcat
进行搭建服务的,而最新版tomcat
依赖jdk 1.8
, 故
- 配置
java
环境 jdk
需要是1.8
版本
2. 运行
进入bin
目录下,可以发现以下内容 :
windows
下 可以通过.bat
和.exe
进行操作linux
与macOS
可以通过.sh
文件操作
通过两种方式可以进行使用 artifactory
:
- 安装方式 及
installService
和uninstallService
- 非安装方式 :直接使用命令
artifactory.ssh
或artifactory.bat
我这里仅仅使用的是非安装方式进行实现;
进入bin目录,执行下面命令(macOS) :
windows双击artifactory.bat运行成功的标志:
验证运行是否成功浏览器访问:浏览器访问:http://localhost:8081/artifactory/ 如果没问题则会出出现引导页面新建 admin
账户密码,如果选择gradle
的话,会生成下面4个Repository
:
3. 上传library
这里以 android
为例,在android studio
中配置library
的 build.gradle
进行上传,共分为3步 :
- 配置项目根目录下的
build.gradle
:下面称为root_gradle
- 配置项目下 library下的
build.gradle
: 下面称为library_gradle
- 测试上传
3.1 配置 root_gradle
3.2.1 apply plugin
apply plugin: 'com.jfrog.artifactory'apply plugin: 'maven-publish'
3.2.2 setting pom
def MAVEN_LOCAL_PATH ='http://localhost:8081/artifactory'def ARTIFACT_ID = 'zcmain'def VERSION_NAME = '1.0.0'def GROUP_ID = 'com.zc.zcmain'publishing { publications { aar(MavenPublication) { groupId GROUP_ID version = VERSION_NAME artifactId ARTIFACT_ID //知道上传包的位置 artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") pom.withXml { def dependencies = asNode().appendNode('dependencies') configurations.compile.allDependencies.each{ // 如果有compile fileTree(),group会为空,需要去除 if(it.group != null) { def dependency = dependencies.appendNode('dependency') dependency.appendNode('groupId', it.group) dependency.appendNode('artifactId', it.name) dependency.appendNode('version', it.version) } } } } }}
3.2.3 setting artifactorypublish
artifactory { contextUrl = MAVEN_LOCAL_PATH publish { repository { // The Artifactory repository key to publish to repoKey = 'gradle-release-local' username = "zcmain" //账户 password = "pass123456" //密码 } defaults { // Tell the Artifactory Plugin which artifacts should be published to Artifactory. publications('aar') publishArtifacts = true // Properties to be attached to the published artifacts. properties = ['qa.level': 'basic', 'dev.team': 'core'] // Publish generated POM files to Artifactory (true by default) publishPom = true } }}
artifactory_user=${security.getCurrentUsername()}artifactory_password=${security.getEncryptedPassword()!"insert password"}artifactory_contextUrl=http://localhost:8081/artifactory
3.2.4 完整的gradle配置
这里说明几点 :
- 在这里上传的事
release.aar
包,故执行命令的时候需要执行release
打包 artifactory/publish/repository/repokey
是你要上传的respository
名称,当然可以新建
apply plugin: 'com.android.library'apply plugin: 'com.jfrog.artifactory'apply plugin: 'maven-publish'def MAVEN_LOCAL_PATH ='http://localhost:8081/artifactory'def ARTIFACT_ID = 'libararya'def VERSION_NAME = '1.0.0'def GROUP_ID = 'com.zc.zcmain'publishing { publications { aar(MavenPublication) { groupId GROUP_ID version = VERSION_NAME artifactId ARTIFACT_ID // Tell maven to prepare the generated "*.aar" file for publishing artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") pom.withXml { def dependencies = asNode().appendNode('dependencies') configurations.compile.allDependencies.each{ // 如果有compile fileTree(),group会为空,需要去除 if(it.group != null) { def dependency = dependencies.appendNode('dependency') dependency.appendNode('groupId', it.group) dependency.appendNode('artifactId', it.name) dependency.appendNode('version', it.version) } } } } }}artifactory { contextUrl = MAVEN_LOCAL_PATH publish { repository { // The Artifactory repository key to publish to repoKey = 'gradle-release-local' username = "zcmain" password = "pass123456 defaults { // Tell the Artifactory Plugin which artifacts should be published to Artifactory. publications('aar') publishArtifacts = true // Properties to be attached to the published artifacts. properties = ['qa.level': 'basic', 'dev.team': 'core'] // Publish generated POM files to Artifactory (true by default) publishPom = true } }}android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { minSdkVersion 18 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }}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:25.3.0' testCompile 'junit:junit:4.12'}
3.3 测试上传
- 命令上传
- 图形化
步骤如下 :
- assembleRelease : 打release 包
- generatePomFileForAarPublication : 生成 pom.xml 文件
- artifactoryPublish :上传
命令顺序执行图形化命令即可;
成功后,登录 Jfrog Artifactory 查看文件:4. 测试使用
使用分下面步骤实现:
- 配置 仓库地址 : root_gradle
- 依赖配置 : app_gradle
- 使用
4.1 配置root_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' }}allprojects { repositories { jcenter() //配置本地仓库 maven { url "http://localhost:8081/artifactory/gradle-release-local/" } }}task clean(type: Delete) { delete rootProject.buildDir}
4.2 配置 app_gradle
重新Rebuild后可件库文件已经被引入项目:
com.zc.zcmain:librarya:1.0.0
基本组成为:group_id:artifact_Id:version_name
- group_id : com.zc.zcmain
- artifact_id : libararya
- version_name: 1.0.0
原文地址
参考:
搭建一个本地jFrog Artifactory并上传库文件
30分钟搭建一个android的私有Maven仓库
ArtifactoryExample
阅读全文
0 0
- 使用Artifactory搭建私有Maven仓库
- 使用Artifactory搭建本地maven仓库
- 使用Artifactory搭建本地maven仓库
- Maven仓库artifactory使用
- Maven 仓库使用与私有仓库搭建
- 使用Archiva搭建Maven私有仓库
- 使用Nexus搭建Maven私有仓库
- centos使用nexus搭建私有maven仓库
- Maven 私有仓库搭建
- 搭建Maven私有仓库
- Maven仓库管理:Artifactory
- 【Maven】Nexus3搭建Maven私有仓库及使用
- 搭建maven私有仓库(Archiva)
- Maven本地私有仓库搭建
- Nexus 搭建maven 私有仓库
- Nexus搭建Maven私有仓库
- Nexus搭建Maven私有仓库
- Nexus搭建私有maven仓库
- 浅谈CSRF攻击方式
- 转眼又是一年国庆节和中秋节,假日好好休息一下,不想太累!
- css定位
- HDU 1596 find the safest road
- C数据结构-线性表之单链表
- 使用Artifactory搭建私有Maven仓库
- 深度学习 ubuntu16.04 theano tensorflow cuda cudnn 搭建gpu加速,亲测有效
- mysql中通过时间/日期/时间日期类型条件查询
- jar命令的用法详解
- 0929 Spring框架
- 第四周项目5---猴子选大王
- java按字节、字符、行、随机读取文件,并设置字符编码格式
- 项目结构
- RabbitMQ Simulator(模拟器)