Nexus 3 upload Maven dependency


When developing in the Intranet environment, it is extremely unfriendly to Maven and other projects, because it cannot be connected to the Maven central warehouse, so the existing solution is to build a maven private library (of course, if you want to import all packages through LIB). After using nexus to build and configure, you will get a brand-new Maven warehouse. There is no dependence, which is more desolate than Mars.
There are two ways to reclaim this barren land.

Method 1 batch upload

With the increasing complexity of business functions and the universal application of microservice architecture, the third-party packages relied on in the development process are not like I can count them with one hand when I did my homework in college. The local Maven library corresponding to the project is often hundreds of megabytes, which requires a simple and fast method to put hundreds of dependencies on the private library.

  1. Ensure that the project is error free in the local Maven environment;
  2. Enter the local Maven library
    Nexus 3 upload Maven dependency
  3. Create a new sh script (the script was found on the Internet, but I don’t remember where to find it)

    # copy and run this script to the root of the repository directory containing files
    # this script attempts to exclude uploading itself explicitly so the script name is important
    # Get command line params
    while getopts ":r:u:p:" opt; do
     case $opt in
         r) REPO_URL="$OPTARG"
         u) USERNAME="$OPTARG"
         p) PASSWORD="$OPTARG"
    find . -type f -not -path './mavenUpload\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;

    Script creation completed
    Nexus 3 upload Maven dependency
    4. Execute this script in the current directory and add the account, password and address of Maven private database

./ -u admin -p admin -r http://IP:PORT/repository/dataservice/

After execution, refresh the Maven library and you can see the uploaded package.

My local Maven library occupies 200m disk, and uploading takes about five minutes.

Method: dynamic upload

When our Maven library has taken shape and only one or two dependencies are missing, we add dependencies by manually uploading.

  1. Find our new Maven library
    Nexus 3 upload Maven dependency
  2. Click enter and click the upload button in the upper left corner (if you don’t have this button, please log in to an account with upload permission). Of course, the upload in the menu on the left can also be uploaded, and the function is the same as here
    Nexus 3 upload Maven dependency
    3. On the upload page, we select the jar we want to upload through the Browse button. For example, we want to upload a MySQL driver package. After uploading, be sure to pay attention to the classifier. If there is a value, remove it manually.
    Nexus 3 upload Maven dependency
    The following group ID, artificiat ID and version need to be filled in manually. The last generate a POM file with these coordinates must be checked and the following packaging must be filled in, otherwise the jar package cannot be downloaded locally. For students who do not know the content of packaging, you can find the POM file corresponding to the current jar package in the local warehouse. It is generally explained in it. If not, jar will be written by default.
    Nexus 3 upload Maven dependency

Of course, as long as it is a person, there will always be errors, so avoid manual input as much as possible. After importing the jar file, add an asset and import the POM file together, so as to avoid the errors of manual input.

Nexus 3 upload Maven dependency

Finally, check the dependency of successful upload in the warehouse and check whether there is a POM file.
Nexus 3 upload Maven dependency

Finally, the packages can be downloaded smoothly, but the Maven plug-in is non violent and can not provide download. Therefore, the private database address is added to the Maven configuration, and the label < mirrorof > Central < / mirrorof > is added emphatically.

In this way, the dependencies of local projects and Maven plug-ins are restored to normal.

Finally, I think of a line from Mars rescue:
Nexus 3 upload Maven dependency