How do I configure my Gradle build to publish artifacts to Nexus?

Easy. Here's an example of a build.gradle file that configures a build to publish artifacts to a snapshot repository. As you can see the publish URL, credentials, and artifact identifiers for this project are all contained in the uploadArchives configuration section.

apply plugin: 'java'
apply plugin: 'maven'

repositories {
    maven {
          url "http://localhost:8081/nexus/content/groups/public"
    }
}

dependencies {
    testCompile "junit:junit:3.8.1"
    compile "org.jbundle.util:org.jbundle.util.jbackup:2.0.0"
    compile "net.sf.webtestfixtures:webtestfixtures:2.0.1.3"
}

uploadArchives {
    repositories {
       mavenDeployer {
             repository(url: "http://localhost:8081/nexus/content/repositories/snapshots") {
             authentication(userName: "admin", password: "admin123")
}
             pom.version = "1.0-SNAPSHOT"
             pom.artifactId = "simple-project"
             pom.groupId = "com.example"
       }
    }
}

To upload artifacts from this project, run "gradle upload"

Have more questions? Submit a request

5 Comments

  • 0
    Avatar
    Peter Kahn

    What might cause gradle to upload to  mirror url instead of  snapshots url?   In settings mirror and snapshots are defined. When I download I use the groups/public url.  When I upload I specify repo url and id for snapshots but see a 400 error after gradle attempts to upload to the groups url.

     

    Any suggestions?

    Thanks

    Peter

  • 0
    Avatar
    Landon Cooper

    Do you have any sample scripts that will allow the deploy of multiple artifacts? Say I have 16 artifacts I need.  Do you have a script that will crawl through a directory and deploy any poms that it identifies? I know this can be done through Rsync...but have a desire to take a different approach to it.   Any information you could provide would be appreciated.

     

    Thanks

    Landon 

  • 0
    Avatar
    Rakesh Reddy

    What protocol does uploadArchive task in gradle use ? I know a build tool such as gradle use GET, to resolve dependencies form Nexus or any repository during compileJava or test tasks. I wanted to know what protocol does gradle use when publishing/distributing the built war file to repository ? Because, my gradle tasks are working find until :war. But, when it gets to uploadArchive, build fails with "Connection time out error".

    Note: By build tool is behind proxy. But can successfully resolve dependencies using GET http.

    When there is a good connection between my Nexus repository and gradle during compile/test tasks via proxy, why not during uploadArchive ?

    Any help ? Highly appreciated.

  • 0
    Avatar
    Rich Seddon

    Gradle uses HTTP PUT requests to upload archives.

     

     

  • 0
    Avatar
    Peter Lynch

    We are closing this article for comments.

    If you have a support license, please contact us by submitting a support ticket.

    If you do not have a support license, please use our Nexus Users List or our other free support resources.

Article is closed for comments.
Powered by Zendesk