One, foreword

With the increase of the project and the number of developers, there will be many problems, such as serious coupling of functional modules and slow construction…. , we generally solve these problems through componentization (splitting various components according to functions, such as data storage, network layer and log, each component can be a separate module), plug-in (one business and one project, each business independently compiled and run, more by ourselves), etc.

So how do we manage these component plug-in classes? This is how to build a private Maven library,

For example, package a utility class library or a function module or a plug-in into Maven. The Maven library can be imported from your company’s Intranet server. This unified management greatly improved our development efficiency, and code management.

2. Build maven private library by Nexus

1, the official website to download address: www.sonatype.com/download-os… , select the version of your system to download.

  

2. After downloading and decompressing, execute the first two commands in the song directory to start the service.

  • Run nexus.bat install to install the Nexus
  • Run nexus.bat start to start the Nexus
  • Nexus. bat stop Stop nexus.bat restart Restart nexus.bat uninstall Uninstall

C: \ Tools \ nexus – 3.12.1-01 – win64 \ nexus – 3.12.1-01 \ bin

Note: CMD must be run with administrator privileges, otherwise it will fail.

3. Open the browser

http://localhost:8081, you can view the management page, default account admin password admin123 Click login



There are four types of warehouses: Hosted Repository: Component used to deploy your own, third party, or public repository Proxy: Proxy remote repository Virtual: A Central M1 virtual repository is provided by default for hosting Maven 2 to Maven 1 Group: Manages multiple warehouses in a unified manner

3. Apache Snapshots: Repositories of third-party releases that cannot be obtained from Public Repositories Central is used to delegate ApacheMaven repository snapshot versions. Central M1 shadow is used to delegate release versions of Maven repository snapshot versions. Used to provide a central repository of M1 format release component image warehouse Codehaus Snapshots: used to proxy CodehausMaven warehouse snapshot version of the components of the Releases: Snapshots: Host-type repositories for deploying and managing internal release artifacts

4. Create a repository



If the repository has multiple deployments, set policy to Allow redeploy. Otherwise, error 403 will occur during subsequent deployments.



After creating a successful copy of the following circled URL, for code upload configuration



Upload repository to Maven repository

Build the aar file before uploading (in the build directory)

1. Add it to gradle.properties of the main project

#Maven repository URL
MAVEN_REPO_RELEASE_URL=http://localhost:8081/repository/ytg/
MAVEN_REPO_SNAPSHOT_URL=http://localhost:8081/repository/ytg/

GroupId for Maven
GROUP =ytg
User name for nexus OSSDE
NEXUS_USERNAME=admin
Password to log in to Nexus OSS
NEXUS_PASSWORD=admin123
# groupid (the name you'll end up quoting)
GROUP_ID =ytg
# type
TYPE = aar
# description
DESCRIPTION = p_commonCopy the code


2. Add it to build.gradlese in module

apply plugin: 'maven'uploadArchives { configuration = configurations.archives repositories { mavenDeployer { snapshotRepository(url: MAVEN_REPO_SNAPSHOT_URL) { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) } repository(url: MAVEN_REPO_RELEASE_URL) { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)} pom.project {// Version'1.0.0'/ / name artifactId'p_common'
                groupId GROUP_ID
                packaging TYPE
                description DESCRIPTION
            }
        }
    }
}
artifacts {
    archives file('p_common.aar'// The name of the aar generated}Copy the code

3, upload



4. Go to the warehouse to check the newly uploaded library file



Four, the use of

1. Build. Gradles in the main project

allprojects {
    repositories {
        google()
        jcenter()
        maven{
            url 'http://localhost:8081/repository/ytg/'}}}Copy the code

2, implementation ‘ytg: p_common: 1.0.0’

Now that the configuration is complete, you can apply the Maven library file you just uploaded to your Android project.

Like to pay attention to the public below it will have more quality resources waiting for you to read!