搭建一个本地jFrog Artifactory并上传库文件
30分钟搭建一个android的私有Maven仓库
ArtifactoryExample
访问该 下载渠道 进行下载 ,截止目前下载的是5.1.4
版本; 下载完毕后进行解压,如下:
mac
下双击可以解压,下面命令进行改名:
$mv jfrog-artifactory-oss-5.1.4 artifactory
由此可见 artfactory
使用的是自带的tomcat
进行搭建服务的,而最新版tomcat
依赖jdk 1.8
, 故
java
环境jdk
需要是 1.8
版本进行bin
目录下,可以发现以下内容 :
windows
下 可以通过 .bat
和.exe
进行操作linux
与 macOS
可以通过.sh
文件操作通过两种方式可以进行使用 artifactory
:
installService
和 uninstallService
artifactory.ssh
或 artifactory.bat
我这里仅仅使用的是非安装方式进行实现;
进入bin目录,执行下面命令(macOS) :
$./artifactory.sh
运行成功的标志:
###########################################################
### Artifactory successfully started (5.442 seconds) ###
###########################################################
浏览器访问:
http://localhost:8081/artifactory/webapp/#/home
会新建 admin
账户密码,如果选择gradle
的话,会生成下面4个Repository
:
这里以 android
为例,在android studio
中配置library
的 build.gradle
进行上传,共分为3步 :
build.gradle
:下面称为 root_gradle
build.gradle
: 下面称为 library_gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// 配置 classpath 使用 4.+ 版本
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def MAVEN_LOCAL_PATH ='http://localhost:8081/artifactory'
def ARTIFACT_ID = 'utils'
def VERSION_NAME = '1.0.7'
def GROUP_ID = 'com.smartahc.test'
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)
}
}
}
}
}
}
artifactory {
contextUrl = MAVEN_LOCAL_PATH
publish {
repository {
// The Artifactory repository key to publish to
repoKey = 'gradle-release-local'
username = "yuan" //账户
password = "labelnet" //密码
}
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
}
}
}
这里仅仅是简单的配置使用,当然你也可以查些高级的使用,比如在 gradle.properties中进行配置的安全性做法,这里就不深入了。
artifactory_user=${security.getCurrentUsername()}
artifactory_password=${security.getEncryptedPassword()!"insert password"}
artifactory_contextUrl=http://localhost:8081/artifactory
这里说明几点 :
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 = 'utils'
def VERSION_NAME = '1.0.8'
def GROUP_ID = 'com.smartahc.test'
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 = "yuan"
password = "labelnet"
}
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'
}
图形化执行,在Android Studio右侧边栏打开library的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
}
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'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
// 依赖配置
compile 'com.smartahc.test:utils:1.0.8'
testCompile 'junit:junit:4.12'
}
说明 :
com.smartahc.test:utils:1.0.8
基本组成为:
group_id:artifact_Id:version_name