2

I'm trying to upload a simple zip to artifactory using gradle. This is my script:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
  }
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

def user = "$System.env.ARTIFACTORY_USER"
def pass = "$System.env.ARTIFACTORY_PASSWORD"

task createArchive(type: Zip){
 baseName 'myzip'
 destinationDir(new File('target'))
 from '.'
 exclude 'target'
 exclude '.gradle'
 exclude 'build.gradle'
 exclude 'README.md'
 doFirst{
  new File('target').mkdirs()
 }
}

task clean(type: Delete){
 delete 'target'
}

publishing {
    publications {
        customArtifact(MavenPublication) {
            artifact createArchive
        }
    }
}

artifactory {
    publish {
        contextUrl = 'http://myrepo/artifactory'
        repository {
            repoKey = "myrepo-tools"
            username = user
            password = pass
        }
        publications ('customArtifact')
    }
}

The code seems to work fine but actually only the build info are published. The zip is not:

Deploying build descriptor to: http://myrepo/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://myrepo/artifactory/webapp/builds/myproject/1503338121156

My code does not seem different from the one published here: How to build Groovy JAR w/ Gradle and publish it to in-house repo (which was pointed as reference in question nothing published to artifactory using gradle artifactory plugin) but I'm not sure that is still valid since is quite old.

The main difference is that almost all the examples are using java plugin so they have the from components.java line in the publications. In my case I cannot use it as I have a custom zip.. but I can't find what else can be changed.

Thanks, Michele.

Mikyjpeg
  • 1,179
  • 1
  • 13
  • 39
  • 2
    The example you are referencing includes a "publications" list inside the "defaults" closure, which tells the Artifactory Plugin which publications should be used for the artifacs deployment. In your case it should probably be publications ('customArtifact') – Eyal Ben Moshe Aug 22 '17 at 05:20
  • Thank for the comment. I tried that but if I use the defaults I got this error: `Could not find method defaults()`. Anyway the publications is inside the `publish` configuration so I expected it to work – Mikyjpeg Aug 22 '17 at 10:39
  • You were right. I was using `defaults` outside of `publish`. So that default element is mandatory (was not clear on docs https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin). Now it worked. Thanks! – Mikyjpeg Aug 23 '17 at 10:36

0 Answers0