Create Maven servers in the enterprise and use Android Studio to publish public projects

Source: Internet
Author: User
Tags maven central sonatype sonatype nexus

Create Maven servers in the enterprise and use Android Studio to publish public projects

Because Android Studio uses the Gradle build tool, the dependent library is introduced as a module (with a complete copy of the library) in the processing of library dependencies ), the ADT of Eclipse directly links libraries as external project dependencies, each of which has its own advantages and disadvantages. The benefit of Android Studio is that it can maintain the integrity of the project at all times. Every project contains everything required by the entire project, when you share a project with others, you will not be unable to open your project because of dropping a library. The disadvantage is that multiple projects depend on the same library. Each project has its own copy of the library code. When the library code needs to be updated, the library code in each project needs to be updated. Eclipse's library dependency only provides a library Link. Multiple projects can be linked to the same library. The advantage is that when the library needs to be modified, you only need to modify one code, if you share a project with others, you may forget to share the library.

Generally, a company's long-term development will summarize its own SDK or tools for its own products. If you use Android Studio for development, once your SDK needs to be updated, you will inevitably encounter problems described above. Fortunately, in addition to library module dependency, Android Studio also provides local repository or remote repository dependency, and uses the Gradle tool to automatically obtain and manage the library required by the project from the repository. Gradle supports maven repositories. in earlier versions, Android Studio directly used maven central repository. Although the official version was later changed to jcenter, custom maven repositories can still be mixed.

Maven official guide _ Chinese full version clear PDF

Maven 3.1.0 release, Project Build Tool

Install Maven in Linux

Maven3.0 configuration and simple use

Set up sun-jdk and Maven2 in Ubuntu

Get started with Maven

The overall solution is divided into three steps:

  • First, build a maven repository on the internal server of your company.
  • Second, release your company's public class library to the maven repository of the company's internal servers.
  • Third, configure the maven repository address of the company's internal server in other projects of the company, and reference the required library. Gradle will automatically obtain it from the maven repository of the server.

1. Build a maven repository on your internal server

Maven repository on the server can be built using Sonatype nexus oss. Sonatype nexus oss is a maven repository management tool that provides a web console for easy deployment and use.

1.1 download sonatype nexus oss

Download sonatype nexus oss to your internal server: http://www.sonatype.org/nexus/go

1.2 install and run sonatype nexus oss

Check whether JDK is installed on the server. JDK 7 or JDK 8 is required for running nexus oss. If JDK is not installed, install JDK first.

The downloaded nexus ossis A zipw.tar.gz compressed package, which needs to be decompressed. You can decompress it to any location. The running of nexus oss has no special requirements on its location. After decompression, you will see two folders, one is the nexus-x.xx.x-xx, and the other is sonatype-work. The nexus-x.xx.x-xx is the home directory of nexus oss, where all running programs and configuration files are in. Sonatype-work is the data directory of nexus-oss, where the maven repository data of the nexus-oss running process is located. Go to the nexus-x.xx.-x-xx/bin directory and run the nexus. bat script directly on the Windows server. The following describes how to install and run the linux platform.

Nexus oss officially recommends installing the nexus-x.xx.x-xx to the/usr/local directory, and make a/usr/local/nexus link pointing to the nexus-x.xx.x-xx directory for later nexus oss version upgrades. The method is as follows:

$ Sudo cp nexus-x.xx.x-xx-bundle.tar.gz/usr/local
$ Cd/usr/local
$ Sudo tar xvzf nexus-x.xx.x-xx-bundle.tar.gz
$ Sudo ln-s nexus-x.xx.x-xx nexus

If you download a zip package, use the sudo unzip nexus-x.xx.x-xx-bundle.zip command to decompress it.

To facilitate future use, you can add the $ NEXUS_HOME environment variable to point to/usr/local/nexus. In addition, by default, the sonatype-work directory is configured in the same directory as the nexus-x.xx.x-xx, if you want to talk about sonatype-work migration to another specified path, you can modify the nexus-x.xx.x-xx/conf/nexus. the nexus-work variable value in the properties configuration file.

After running nexus oss, you only need to run the nexus-x.xx.x-xx/bin/nexus script, the parameter can be console or start. The console prints the running log on the console. If you have configured the NEXUS_HOME environment variable, You can execute the following statement anywhere:

$ NEXUS_HOME/bin/nexus start

1.3 configure sonatype nexus oss

After running successfully, open http: // server address: 8081/nexus in the browser to view the control panel of nexus oss.

Click login logon in the upper right corner. The default account password is admin/admin123. After logging on, you can see the following interface:

On the left side is the function panel. You can view all maven Repositories in Repositories and manage users (change passwords or something) in the User ). Click Repositories to view the maven Repository:

We can see that by default, nexus oss has created several warehouses, each of which has its own attributes.

The first important attribute is the type repository type. There are four main types: group, hosted, proxy, and virtual. Different types of warehouses have different functions and work modes. Generally, you only need to pay attention to the group, hosted, and proxy types. The nexus oss can have multiple maven repositories, but the maven tool requires the use of the groupId: artifactId: version parameter to uniquely identify a project, therefore, the nexus oss uses a group repository to determine the priority of each maven repository on the nexus oss, so as to solve conflicts between different maven with the same project. A proxy repository is actually a proxy used to represent maven Repositories on other servers. The hosted type is the local maven repository of the nexus oss server. It is also the main repository type used this time.

The Repository Path is the Repository address. It is required to publish your project to maven and reference the project in the maven Repository.

After selecting a repository, you can see the details of the repository in the window below. The repository can be set on the Configuration tab.

Our goal is to release our own project to our own server, so we need to select the hosted type warehouse, to avoid code leakage within the company (of course, the server must also be an intranet server, servers that can be accessed through the public network, and released Code may also be at risk ). For the hosted type warehouse we want to use, the key point is the Repository Policy warehouse storage protocol in it. There are two types: release and snapshot. release indicates the release version, and snapshot indicates the snapshot version. There is also a Deployment Policy Deployment protocol, which has three modes: Allow Redeploy (Deployment allowed), Disable Redeploy (Deployment not allowed), and Read Only (Read-Only. Only in Allow Redeploy mode can we have the permission to publish our project to this project. By default, the nexus oss has established two hosted warehouses, Releases and snapshots. We can check the configuration and use it directly. Of course, you can also create your own hosted repository.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.