Publish the module to the local maven repository
- Prepare a directory locally as a maven repository
gradle.properties
Configure warehouse information in the project (mainly POM file information)build.gradle
Configure plugins, tasks, and code information in the module- Execute publishing tasks
- local
maven
view - Reference the package in the local repository
1. Prepare the directory
Example:
E:\libs\localMaven
2. Configure warehouse information
gradle.properties
Configure property information in the project's Example:
# 包信息
PROJ_GROUP= 一般为公司域名
PROJ_VERSION=版本
# 项目的描述
PROJ_WEBSITEURL= 项目地址
PROJ_ISSUETRACKERURL= 提 issue 地址
PROJ_DESCRIPTION= 项目介绍
# Licence信息 这部分是固定的
PROJ_LICENCE_NAME=The Apache Software License, Version 2.0
PROJ_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
PROJ_LICENCE_DEST=repo
# Developer 信息 这里是开发者信息
DEVELOPER_ID=mxc
DEVELOPER_NAME=孟祥超
[email protected]
3. module
Configure plugins, tasks, code information for
For elegance module
, create a gradle.properties
file under the set properties
PROJ_NAME=依赖名字 localrepo
PROJ_ARTIFACTID=所属分类
LOCAL_REPO_URL= 本地仓库的地址:file://+本地路径 ;例如 file://E:/libs/localMaven
Define upload tasks using plugins module
inbuild.gradle
maven
Use maven
plugin
apply plugin: 'maven'
Define upload tasks
uploadArchives {
repositories.mavenDeployer {
repository(url: LOCAL_REPO_URL)
pom.groupId = PROJ_GROUP
pom.artifactId = PROJ_ARTIFACTID
pom.version = android.defaultConfig.versionName
}
}
Example
apply plugin: 'com.android.library'
apply plugin: 'maven'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
repositories{
flatDir{
dirs'libs'
}
}
}
uploadArchives {
repositories.mavenDeployer {
repository(url: LOCAL_REPO_URL)
pom.groupId = PROJ_GROUP
pom.artifactId = PROJ_ARTIFACTID
pom.version = android.defaultConfig.versionName
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
4. Execute the command to start the task
I am the windows
system so using gradlew
localrepo is the local input command module
in Android studio
the Terminal
window
gradlew -p localrepo clean build uploadArchives --info
5. If the execution is successful maven
, there should now be in the local directory
6. Reference local dependencies
Add the local maven
address in the project'sbuild.gradle
allprojects {
repositories {
jcenter()
mavenCentral()
google()
maven { url "https://jitpack.io" }
maven{
url 'file://E:/libs/localMaven/'
}
}
}
add dependencies moudle
onbuild.gradle
implementation 'cn.sintoon:localrepo:1.0'
end