Use Nexus to build a private MAVEN library to manage internal lib,get!

Source: Internet
Author: User
Tags sonatype

1. Introduction of this article

Most of the time, we are compile's AAR or jar, or module within the project. But did you find it inconvenient? If someone changes the code in the public library, either re-copy the AAR or the jar and send it back to the new one. If the module seems to be all right, change it directly on the module, then continue pulling the code from git. However, if multiple projects are to be referenced to the same public Lib, the module will be changed by multiple projects at this time. This article is to introduce multi-person multi-project case, how to use the same lib, to achieve a change, multi-project can be updated at the same time. In view of my publication the day before the article just learn how to build, if there is a mistake, look correct!

2. Build Nexus Environment

Download Link: http://www.sonatype.org/nexus/go/(it seems that the official website can not download, face big may try)
http://download.csdn.net/detail/u010716109/9497645
After downloading, unzip, PS: to the official website to download the children's shoes please download nexus-2.13.0-01-bundle.tar.zip, put the extracted files in the directory you want to prevent

1. Configure environment Parameters
in the \bin\jsw\conf directory, open the wrapper.conf file, ctrl+f find the command word, a total of 2 is the following wording. Here are the changes to the wording, children's shoes to replace the following path to their Java JDK directory.
(1) Java application
Wrapper.java.command=c:\java\jdk1.8.0_45\bin\java.exe
(2) Set the JVM executable
( Modify this to absolute path if you need a Java which is not on the OS path)
wrapper.java.command=c:\java\jdk1.8.0_45\b In\java.exe
2. Open cmd.
The CD file name until you jump to the bin directory under your extracted file. (Tip: File name hit several letters, press TAB key, direct completion, so do not knock complex file path)

(1) Enter the Nexus install to display the successful installation wrapper | Nexus installed.
(2) Enter Nexus start and the following content will be displayed successfully. If it fails, show failed to start, then you need to see if Port 8081 is occupied or the path to the Java JDK you just configured is correct

wrapper |  Starting the Nexus Service ...  Wrapper |  Waiting to  start ...  Wrapper |  Waiting to  start ...  Wrapper |  Waiting to  start ...  Wrapper |  Waiting to  start ...  Wrapper |  Waiting to  start ...  Wrapper |  Nexus Started  

Now that the installation configuration is complete, you can proceed to the next step.
3. Start the Nexus local site 127.0.0.1:8081/nexus, if not open, you need to see if 8081 ports are occupied.

4. Building a Warehouse
(1) Click on the log in at the top right, and then enter the account admin, password admin123, login completed click on the left navigation bar repositories, click the Add button on the middle page, select hosted Warehouse. Such as.

(2) Fill in the following red box content, click Save. Warehouse name and ID I write the same.

(3) At this point you can find your new warehouse in the list above. Because I created it in the default warehouse group (click Add under the Public repositories group), the GroupID of the warehouse is public. (It's important to use it for a while)
(4) Open your Lib project and add the following code to the Build.gradle in the corresponding module.
It is important to note that change Ttshop to your own warehouse name, depending on the type of lib you choose, packaging is the AAR or jar package. GroupId and Artifactid is just the site of the name displayed, find and fill in.

Apply plugin:' Com.android.library 'Apply plugin:' maven 'Apply plugin:' signing 'Signing {required {has ("Release") && Gradle.taskGraph.hasTask ("Uploadarchives")} sign configurations.archives}uploadarchives {configuration = configurations.archives Repositories.mavendeplo Yer {beforedeployment {mavendeployment deployment, Signing.signpom (Deployment)} Repository (URL:' http://127.0.0.1:8081/nexus/content/repositories/ttshop/') {//Warehouse addressAuthentication (userName:"Admin",//user namePassword"Admin123")//Password} pom.project {Name' Ttshop 'Packaging' AAR 'Description' None 'Url' http://127.0.0.1:8081/nexus/content/repositories/ttshop/'//Warehouse addressGroupId"Public"Artifactid"Ttshop" //libaVersion1.0}}}android {Compilesdkversion atBuildtoolsversion"23.0.1"Defaultconfig {minsdkversion -Targetsdkversion atVersioncode1Versionname"1.0"} buildtypes {release {minifyenabledfalseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}}dependencies {compile filetree (include: [' *.jar '],dir:' Libs ') Compile' com.android.support:appcompat-v7:23.1.1 'Compile' com.android.support:design:23.1.1 '}

(5) Execute gradlew Tasks command in terminal in Android studio, compile Lib, generate AAR. PS: Other tips why write execution./gradlew Tasks command, I don't know, I can't do it anyway. Then Gradlew uploadarchives instructions, upload files to the warehouse. During the execution of this instruction, you may be prompted to download the Gradle file, it takes a long time to download, and it takes me more than 10 minutes.

After uploading successfully, we can find your warehouse group in the Nexus installation directory, for example, my E:\english_soft_maven_tool\sonatype-work\nexus\storage is public, Then open in public will see the Ttshop folder, there will be uploaded files. is viewed at the Nexus site.

Since then, build the environment and upload and save the file to complete. Here are some small benefits to give, please check the surrounding environment, then turn down! High-energy Warning!

3, the specific use way

Add the MAVEN statement to the project Build.gradle in the project where you want to reference the library. Not the Build.gradle in the app directory. 127.0.0.1 can be changed to the IP address of your MAVEN private library so that other machines can synchronize Lib in the repository

allprojects {    repositories {        jcenter()        mavenCentral()        //这里加入自己的maven地址,其它机器要输入正确的IP地址,本地就用127.0.0.1        maven {            "http://127.0.0.1:8081/nexus/content/repositories/ttshop/"        }    }}

Then in the app directory, add the Build.gradle directory to compile ' Public:ttshop:[email protected] ' Application Library declaration, and then sync now.

dependencies {    compile‘public:ttshop:1.0@aar‘}

Feel useful please order a praise, thank you. Share please indicate the source.
Related articles recommended:
Http://www.open-open.com/lib/view/open1434522817864.html
http://techtalk.alo7.com/?p=220

Use Nexus to build a private MAVEN library to manage internal lib,get!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.