jfrog / jfrog-cli

JFrog CLI is a client that provides a simple interface that automates access to the JFrog products.
https://www.jfrog.com/confluence/display/CLI/JFrog+CLI
Apache License 2.0
538 stars 236 forks source link

1.33.1 no longer publishes multiple classifier artifacts in gradle builds #627

Open alexmnyc opened 4 years ago

alexmnyc commented 4 years ago

Describe the bug 1.33.1 no longer publishes multiple classifier artifacts in gradle builds

To Reproduce

build.gradle

...
publishing {
    publications {
        shadowJar(MavenPublication) { publication ->
            project.shadow.component(publication)
            artifact schemaZip {
                classifier "schema"
            }
            artifact hookZip {
                classifier "hook"
            }
        }
    }
}
...

JFROG:
jfrog rt gradle "build artifactoryPublish"

Expected behavior All classifier artifacts are published

Screenshots

Versions

Additional context Add any other context about the problem here.

yahavi commented 4 years ago

Thanks for reporting this issue, @alexmnyc! We are working on reproducing it.

One thing I noticed is the Gradle tasks - I don't think the build task is necessary. You should try just artifactoryPublish.

Please help us to resolve this quickly by providing:

  1. A minimal working example - A complete minimal build.gradle file that we can run using artifactoryPublish.
  2. Please explain exactly what does it mean "multiple classifiers". Can you publish one classifier artifact? Like this example:
    publishing {
    publications {
        shadowJar(MavenPublication) { publication ->
            project.shadow.component(publication)
            artifact schemaZip {
                classifier "schema"
            }
        }
    }
    }
  3. Your Gradle version.
  4. The last JFrog CLI version that did publish classifier artifacts.
alexmnyc commented 4 years ago
  1. A minimal working example - A complete minimal build.gradle file that we can run using artifactoryPublish.

plugins { id 'java' id 'maven-publish' id 'com.github.johnrengelman.shadow' version '5.1.0' } task schemaZip(dependsOn: tasks.shadowJar, type: Zip) { group = "${project.group}" classifier "schema" description = "Builds -${classifier} archive containing database schema " from('src/main/resources/liquibase') { into "liquibase" } }

task preReceiveHook(dependsOn: tasks.shadowJar, type: Zip) { group = "${project.group}" classifier "pre-receive-hook" description = "Builds -${classifier} archive containing pre-receive hook" from('docker/hooks/pre-receive.d/python.template') { into "pre-receive.d" } }

tasks.build.dependsOn tasks.shadowJar, tasks.schemaZip, tasks.preReceiveHook

publishing { publications { shadowJar(MavenPublication) { publication -> project.shadow.component(publication) artifact schemaZip { classifier "schema" } artifact hookZip { classifier "hook" } } } }

artifacts { archives distZip archives schemaZip archives preReceiveHook }

shadowJar { classifier = "" baseName = 'service' }


> 2. Please explain exactly what does it mean "multiple classifiers". Can you publish one classifier artifact? Like this example:
> 
 ```groovy
 publishing {
     publications {
         shadowJar(MavenPublication) { publication ->
             project.shadow.component(publication)
             artifact schemaZip {
                 classifier "schema"
             }
             artifact hookZip {
                classifier "hook"
            }
         }
     }
 }
  1. Your Gradle version. gradle 6.3

  2. The last JFrog CLI version that did publish classifier artifacts. 1.32.4

yahavi commented 4 years ago

Thanks, @alexmnyc. I tried your example, but it fails with the following error:

> No signature of method: build_9eoy8rnd7p8n327bptkf2mq0s.publishing() is applicable for argument types: (build_9eoy8rnd7p8n327bptkf2mq0s$_run_closure3) values: [build_9eoy8rnd7p8n327bptkf2mq0s$_run_closure3@190e90c3]

It looks like it doesn't know hookZip and distZip

yahavi commented 4 years ago

@alexmnyc I think I managed to reproduce this issue, however it not exactly as you described.

In version < 1.32.4 all publication were published. In version >= 1.33.1 only the mavenJava publication is published. As a results, instead of publishing your shadowJar publications, the default mavenJava publication is published - no custom artifacts are published. (Please approve/disapprove). As a workaround, can you try to change shadowJar to mavenJava. If you agree with this, I have a fix ready for deploy: https://github.com/yahavi/build-info/commit/a0ea88c5a29e5acff3017e01feb69fc65dc21b61.

Thanks again and we'll appreciate your feedback for this!

alexmnyc commented 4 years ago

@yahavi is there a merge request you would like me to approve?

yahavi commented 4 years ago

No @alexmnyc, I just need more information from you:

  1. Does it work with 1 classifier artifact?
  2. Can you please try to change shadowJar to mavenJava and report here if it worked?

Thanks!

alexmnyc commented 4 years ago

Sure thing.

could you please be explicit?

  1. Does it work with 1 classifier artifact?

like here?

publishing {
    publications {
        shadowJar(MavenPublication) { publication ->
            project.shadow.component(publication)
        }
    }
}

Can you please try to change shadowJar to mavenJava and report here if it worked?

Could you please provide me with an example you would like me to try? I need to be publishing fat jars not maven publications of this artifact

yahavi commented 4 years ago

@alexmnyc I had a discussion about this issue with my team members. JFrog CLI can run Gradle with one of the 2 following methods:

  1. Gradle Artifactory plugin applied in Gradle build script.
  2. Gradle Artifactory plugin does not applied in Gradle build script.

In method (1), you can specify your publications in the Artifactory block using the Gradle Artifactory plugin. For example here we tell the CLI to publish the 'mavenJava' publication. In your example, you can state your 'shadowJar' publication instead. This is for more advanced users, generally speaking. Gradle Artifactory plugin documentation.

In method (2) like here and in your example, JFrog CLI does most of the work for you. It applies the Gradle Artifactory plugin and builds the 'Artifactory' block behind the scenes. However it can't know which publication to publish. It has default 'mavenJava' and 'ivyJava' publications:

mavenJava(MavenPublication) {
    from components.java
}
ivyJava(IvyPublication) {
    from components.java
}

These default publications publish the final jars, pom.xml, Ivy files and some metadata files. Using method (2) does not overrides 'mavenJava' and 'ivyJava' publication if they are exist. In other words - if you change the name of your publication from 'shadowJar' to 'mavenJava' your artifacts are expected to be published.

Before Gradle Artifactory plugin 4.11.0 and JFrog CLI 1.32.4, we published Gradle projects using the deprecated maven plugin (more information here). In JFrog CLI 1.32.4 we started to apply the new maven-publish plugin. Since we are using the new method to publish, your artifacts stated in the 'artifacts' block are not published as before. Running Gradle builds with JFrog CLI.

For you, we'd recommend to change the name of the 'shadowJar' publication to 'mavenJava' publication. If you have more publications, we would recommend you to use method (1).

Some good examples can be found here.

Please let us know if it helped.

alexmnyc commented 4 years ago

Publishing shadowjar fat jar requires a setup like this https://imperceptiblethoughts.com/shadow/publishing/#publishing-with-maven-publish-plugin

I am not sure how changing shadow to maven is going to solve my problem as I am trying to publish a shadow jar using the prescribed method below

publishing {
  publications {
    shadow(MavenPublication) { publication ->
      project.shadow.component(publication)
    }
  }
  repositories {
    maven {
      url "http://repo.myorg.com"
    }
  }
}

I have a custom shadowJar task configuration

shadowJar {
    classifier = ''
    baseName = 'my-service'
    mergeServiceFiles('reference.conf')
}

task schemaZip(dependsOn: tasks.shadowJar, type: Zip) {
    classifier "schema"
    description = "Builds -${classifier} archive containing database schema "
    from('src/main/resources/liquibase') { into "liquibase" }
}

and then using a standard publishing block to publish both artifacts


artifacts {
    archives distZip
    archives schemaZip
}

publishing {
    publications {
        shadowJar(MavenPublication) { publication ->
            project.shadow.component(publication)
            artifact schemaZip {
                classifier "schema"
            }
        }
    }
}