1
votes

I am currently having a problem when publishing a Gradle build to a snapshot Artifactory repository where 'SNAPSHOT' is not being resolved to a timestamp. The jars can be found on the repo but are in the format of '1.0.1-SNAPSHOT.jar' instead of e.g. '1.0.1-20180420.112216-1.jar'. This is causing problems when other builds depend on the project in question. We currently have Maven builds which are pushing to the same repo without any problems.

I am using the maven-publish and com.jfrog.artifactory plugins. It is worth mentioning that I don't have a lot of Gradle experience.

Relevant pieces from build.gradle:

apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

artifactory {

  contextUrl = ${rep.url}
  publish {
      ext.systemProperties = System.getenv()
      println "Publishing using this user: ${systemProperties.artifactory_user}"
      println "Publishing to this repo: ${systemProperties.artifactory_repo}"
      repository {
         repoKey = "${systemProperties.artifactory_repo}"
         username = "${systemProperties.artifactory_user}"
         password = "${systemProperties.artifactory_password}"
         maven = true
      }
      defaults {
        publications('mavenJava')
      }
  }
}

publishing {
   publications {
      mavenJava(MavenPublication) {
        from components.java
      }
   }
}

relevant from gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-bin.zip

Environment variables come from Jenkins and are the same used in our maven builds.

1

1 Answers

0
votes

I don't see where you actually set your jar name in the code at all. The Gradle doc for the Maven Publishing plugin tells you how you can customize the publication identity of your artifact:

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId 'org.gradle.sample' // Modify the artifact group
            artifactId 'project1-sample'// Modify the artifact name
            version '1.1'   // Modify the artifact version

            from components.java
        }
    }
}

If you are not overriding these values in the publishing closure as shown above, the default values of the project are being used for naming the artifact which is defined by the group and version properties of your project. The default version value is version '1.0-SNAPSHOT' if you start a Gradle project from scratch in IntelliJ for example.

The following code should help you to resolve your issue:

publishing {
    publications {
        mavenJava(MavenPublication) {
            version 'your_time_stamp'

            from components.java
        }
    }
}