Publish Snapshot vs Publish Release in Gradle With Continuous Integration

dev picture dev · May 25, 2013 · Viewed 37.4k times · Source

I'm just learning Gradle, coming from both an Ant+Ivy and Maven background and I'm trying to wrap my head around the proper way to publish a release version of my software using gradle. I also need to constantly integrate my projects without having to constantly release independent artifacts.

Ant + Ivy

In the Ant + Ivy world, I can create publishSnapshot and publishRelease targets. These can each use different Ivy resolvers to resolve and publish to my separate snapshot or release repositories in Nexus.

Maven

With Maven, I can define a snapshotRepository or repository in my distributionManagement section to have maven publish to my separate snapshot or release repositories in Nexus.

Gradle

Now enter gradle. How can I achieve this same functionality? I am using ivy style repositories.

Thank you for any insights you can provide.

ANSWER

Thanks to René's answer below, I was finally able to create a workable solution. The crux of the matter was that I needed to constantly integrate across all my projects. To do this I thought that declaring a dependency using version number latest.integration was the only way to pull in the latest version of my libraries, and therefore I needed to use ivy style repositories.

In fact, there are other ways to pull in the latest version of libraries in order to continuously integrate my software across all projects. The solution is to use the uploadArchives exactly as René has listed below (also note you will need to apply plugin: 'maven' for this to work. Make sure your repositories are also maven style, and when declaring a dependency, you can use dynamic version numbers as shown here. In my case, I listed a global version number in my common.gradle and in downstream projects, I used version: version to reference the global version variable. In this way, each artifact in my system has the same version. When it's time to release, I can change this from 1.0-SNAPSHOT to 1.0 and build each one in order.

Answer

Rene Groeschke picture Rene Groeschke · May 27, 2013

You can configure the snapshot and the release repository in the 'Upload' task (e.g. the uploadArchives) task:

uploadArchives {  
    repositories {  
        mavenDeployer {  
            repository(url: 'http://myCompanyRepo.com:8081/releases') {  
                authentication(userName: 'admin', password: 'password');  
            }  
            snapshotRepository(url: 'http://myCompanyRepo.com:8081/snapshots') {
                authentication(userName: 'admin', password: 'password');  
            }  
        }  
    }  
}

For *-SNAPSHOT versions the snapshotRepository is used. Otherwise the releases repo is used.