Publish the Library module to the local maven repository using Gradle

Publish the module to the local maven repository

  1. Prepare a directory locally as a maven repository
  2. gradle.propertiesConfigure warehouse information in the project (mainly POM file information)
  3. build.gradleConfigure plugins, tasks, and code information in the module
  4. Execute publishing tasks
  5. local mavenview
  6. Reference the package in the local repository

1. Prepare the directory

Example:

E:\libs\localMaven

2. Configure warehouse information

gradle.propertiesConfigure 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. moduleConfigure plugins, tasks, code information for

For elegance module, create a gradle.propertiesfile under the set properties

PROJ_NAME=依赖名字 localrepo
PROJ_ARTIFACTID=所属分类

LOCAL_REPO_URL= 本地仓库的地址:file://+本地路径 ;例如 file://E:/libs/localMaven

Define upload tasks using plugins moduleinbuild.gradlemaven

Use mavenplugin

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 windowssystem so using gradlew localrepo is the local input command modulein Android studiothe Terminalwindow

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 mavenaddress in the project'sbuild.gradle

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        google()
        maven { url "https://jitpack.io" }
        maven{
            url 'file://E:/libs/localMaven/'
        }
    }
}

add dependencies moudleonbuild.gradle

 implementation 'cn.sintoon:localrepo:1.0'

end

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324417190&siteId=291194637