Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish Snapshot vs Publish Release in Gradle With Continuous Integration

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.

like image 753
dev Avatar asked May 25 '13 13:05

dev


People also ask

What is the difference between snapshot and release?

By definition, snapshots are mutable, releases are immutable. This is why Nexus makes you store them separately because usually you don't care if you lose snapshots, but you will care if you lose releases. It makes snapshot cleanup much easier to deal with that way.

What does gradle release do?

The gradle-release plugin is designed to work similar to the Maven release plugin. The gradle release task defines the following as the default release process: The plugin checks for any un-committed files (Added, modified, removed, or un-versioned). Checks for any incoming or outgoing changes.

What is publishing in gradle?

Gradle automatically generates publishing tasks for all possible combinations of publication and repository, allowing you to publish any artifact to any repository.

How do I publish a project in Gradle?

What follows is a practical example that demonstrates the entire publishing process. The first step in publishing, irrespective of your project type, is to apply the appropriate publishing plugin. As mentioned in the introduction, Gradle supports both Maven and Ivy repositories via the following plugins:

How to configure the snapshot and the release repository?

You can configure the snapshot and the release repository in the 'Upload' task (e.g. the uploadArchives) task: For *-SNAPSHOT versions the snapshotRepository is used. Otherwise the releases repo is used.

How to publish the RPM of an artifact in Gradle?

If you use artifact () with an archive task, Gradle automatically populates the artifact’s metadata with the classifier and extension properties from that task. Now you can publish the RPM.

What is the difference between Ivy and Gradle module metadata?

As of Gradle 6.0, the Gradle Module Metadata will always be published alongside the Ivy XML or Maven POM metadata file. Gradle makes it easy to publish to these types of repository by providing some prepackaged infrastructure in the form of the Maven Publish Plugin and the Ivy Publish Plugin.


2 Answers

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.

like image 121
Rene Groeschke Avatar answered Sep 23 '22 09:09

Rene Groeschke


If you want to use the new maven-publish plugin, you can upload to different repositories using an if statement:

apply plugin: 'maven-publish'  ...  publishing {     publications {         mavenJava(MavenPublication) {             from components.java         }     }     repositories {         maven {             credentials {                 username "anonymous"             }                          if(project.version.endsWith('-SNAPSHOT')) {                 url "http://example/artifactory/libs-snapshot-local"             } else {                 url "http://example/artifactory/libs-release-local"             }         }     } } 

Reference: maven-publish and setting snapshotRepository and releaseRepository

like image 21
Paolo Fulgoni Avatar answered Sep 22 '22 09:09

Paolo Fulgoni