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

2 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 

Please sign in to leave a comment.
Powered by Zendesk