A tentative study of Gradle (iii): Publish Project to Nexus Resource Library

Source: Internet
Author: User

4. Publish the Project

In the development of the company, if you take Maven as a way to build a project, you will typically set up a Nexus maven on the company server, some of the company's accumulated resource components and the Central Library does not provide resources, and some projects will be published in the servers, Developers can then import internal resources through MAVEN at specific development time. So now that you're replacing maven with Gradle, this requirement needs to be met by looking at the official documentation that can be implemented by introducing ' maven-publish '. The following configuration is specifically added:

...

Apply plugin: ' Maven-publish '//Add Maven Publishing plugin

...

//Upload resource configuration

Uploadarchives {

     repositories {

        Mavendeployer {

           //upload resources to maven

            Repository (URL: "http://localhost:8081/nexus/content/repositories/releases/") {

                Authentication (userName: "admin", Password: "admin123")

           }

        pom.version = "$project. Version"

        Pom.artifactid = "$p Roject.name "

        pom.groupid =" $project. Group "

     }

  ;  }

}

By adding the above configuration, you can already publish the project to my local http://localhost:8081/nexus/content/repositories/releases/via the upload command. But here's the problem, I can only publish the project to the local releases library, but what if I'm in the dev or snapshot version of this project?

This is where Gradle is built more flexibly than Maven. The entire Build.gradle file is actually code for a groovy language. When it comes to this, we all understand that, according to different versions published to different libraries, this is not a condition to judge things.

To extract the URL as a variable, add the relevant judgment code, as follows:

Published by default to the MAVEN Nexus release Library

def nexusurl = "http://localhost:8081/nexus/content/repositories/releases/"

If you are publishing a snapshot library for a snapshot version to a MAVEN Nexus

if (Version.endswith ("-snapshot")) {

Nexusurl = "http://localhost:8081/nexus/content/repositories/snapshots/"

}

......

uploadarchives {

......

Upload resources to Maven

Repository (Url:nexusurl) {

Authentication (userName: "admin", Password: "admin123")

}

......

}

OK, now all version number "-snapshot" will be published to the snapshot library, while others will be published to the release library, now perform the next upload look at the effect of it ....


Figure 4.1 Upload command execution results
Figure 4.2 Nexus
Figure 4.3 Resource Details

In addition, after the introduction of ' Maven-publish ', if Mavenlocal () is configured, the resources are also submitted to the local Maven repository at upload.


Figure 4.4 Local resource pool

Summarize

A few hours of trial, no problem, but Gradle's flexibility really impressed me, it is very good to demonstrate that it is better than the principle of configuration. But if you want to play it, you need to learn some groovy language. There is a time cost here compared to the program apes that understand XML. And because it is very flexible, and it is very likely that the configuration of confusion, but the overall still feel that the advantages outweigh the disadvantages. I'm tired of configuring XML, writing code in configuration, thinking it's fun ...

A tentative study of Gradle (iii): Publish Project to Nexus Resource Library

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.