8
votes

In our artifactory we have a snapshot repo defined to handle max 5 unique snapshots. We added -SNAPSHOT-.extension to the filename. SNAPSHOT gets also converted to timestamp. Build is done with gradle and artifact gets published with bamboo and artifactory plugin.

A file deployed to artifactory ...

inhouse-snapshots:com/example/project/subproject/trunk-SNAPSHOT/subproject-trunk-SNAPSHOT-79.amp

becomes ...

inhouse-snapshots:com/example/project/subproject/trunk-SNAPSHOT/subproject-trunk-20120321.154621-1-79.amp

This is fine and every build adds a new file with incremented build number, but the timestamp-number always stays 20120321.154621-1 so we have a file list like:

  • subproject-trunk-20120321.154621-1-79.amp
  • subproject-trunk-20120321.154621-1-80.amp
  • subproject-trunk-20120321.154621-1-81.amp

Anybody has a solution or suggestion for a another directory layout?

2
This snapshot timestamp replacement shouldn't happen in Artifactory. Artifactory only replaces the snapshots of artifacts that are deployed to a valid Maven standard path (this example isn't valid) in a repository with the default Maven layout. What layout is your repository configured to use? Do you perform the replacement yourself?noamt
The repository layout is maven2default and i did not perform the snapshot replacment. I tested the paths above with the path tester in artifactory admin console, nearly everything is fine expect the build numbers 79, 80, ... are recognized as classifiers. I'm not sure if this is correct. I also tested it without build numbers, in this case the artifact will be overwritten. There i would expect a second file with a new timestamp and a -2 ... at the end of the timestampchris.ingenhaag
Oh I just recognized my typo above that causes the invalid maven2 path, fixed it. Sorrychris.ingenhaag

2 Answers

11
votes

As you've correctly observed, the build number you've attach to the deployed file name is identified as a classifier; this is because Maven doesn't specify a build number with a non-unique snapshot.

Artifactory maintains the same combination of timestamp and build number for "batches" of artifacts and "bumps" the timestamp and build number when it detects a new "batch"; there are 2 ways in which Artifactory detects artifact "batches" for the purpose of converting non-unique to unique snapshots:

  1. Artifacts are deployed in the exact order of: artifact (no classifier), POM, attached artifacts (with classifiers); The first ordinary artifact to be deployed after the a POM will create a new "batch"; hence providing a new timestamp and builder number.

  2. Artifacts deployed with a matrix param of the key "build.timestamp" and a value of a millisecond-based epoch timestamp; Artifacts with same timestamp values will be associated under the same "batch".

You should either omit the build number from the deployed file and deploy it with a "build.timestamp" matrix param (to make Artifactory bump the "batch" on each new deployment) or deploy the files already with the unique snapshot.

0
votes

I posted this solution: https://discuss.gradle.org/t/2-8-2-9-mavendeployer-doesnt-honour-uniqueversion-false-in-maven-uploadarchives/13370/8 The issue I had was multiple publications in the publishing section. The solution for me was to add the extra artifacts to the one publication. Then all of the items, api jar, source jar, api source jar and main jar have the same timestamp for a SNAPSHOT. This seems to take care of the build.timestamp automatically for me.

task apiJar(type: Jar) {
    classifier = 'api'
    from(sourceSets.main.output) {
        include "com/company/app/dto/**"
    }
}

task sourceJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task apiSourceJar(type: Jar, dependsOn: classes) {
    classifier = 'api-sources'
    from(sourceSets.main.allSource) {
        include "com/company/app/dto/**"
    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            pom.withXml {
                asNode().appendNode('description', 'APP Sprint Boot App')
            }
            artifact apiJar
            artifact sourceJar
            artifact apiSourceJar
        }
    }
    repositories {
        maven {
            credentials {
                username = 'username'
                password = 'password'
            }
            if(project.version.endsWith('-SNAPSHOT')) {
                url "http://server:9081/artifactory/libs-snapshot-local"
            } else {
                url "http://server:9081/artifactory/libs-release-local"
            }
        }
    }
}