jfrog / artifactory-gradle-plugin

JFrog Gradle plugin for Build Info extraction and Artifactory publishing.
Apache License 2.0
20 stars 15 forks source link

Cannot publish Gradle plugins with Artifactory plugin since version 5.1.11 #87

Closed mricciuti closed 7 months ago

mricciuti commented 8 months ago

Describe the bug

Latest plugin version 5.1.11 introduced some changes in artefact publication descriptor handling to get rid of Gradle deprecated/deleted internal APIs, in order to support Gradle 8.4+ version. (see https://github.com/jfrog/artifactory-gradle-plugin/issues/75) .

A side effect is that it's no longer possible to publish multiple Maven publication artefacts from a single Gradle project: the POM publishing is not correctly handled which makes the artifactoryDeploy task fail.

A example of scenario which now fails with this new plugin version: trying to publish Gradle plugin to a custom repository

Current behavior

When trying to publish a Gradle plugin to a custom Artifactory server (see below for a sample gradle projet setup to reproduce the isssue):

$ ./gradlew artifactoryPublish

> Task :artifactoryPublish
> Task :extractModuleInfo
[pool-22-thread-1] Deploying artifact: https://******/maven-snapshot/org/example/gradle/publishing/sample-plugin-publish/1.0.0-SNAPSHOT/sample-plugin-publish-1.0.0-SNAPSHOT.jar
[pool-22-thread-1] Deploying artifact: https://*******/maven-snapshot/greeting/greeting.gradle.plugin/1.0.0-SNAPSHOT/greeting.gradle.plugin-1.0.0-SNAPSHOT.pom
[pool-22-thread-1] Deploying artifact: https://*******/maven-snapshot/org/example/gradle/publishing/sample-plugin-publish/1.0.0-SNAPSHOT/sample-plugin-publish-1.0.0-SNAPSHOT.pom
Failed to upload file

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':artifactoryDeploy'.
> java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.io.IOException: JFrog service failed. Received 409: {
    "errors" : [ {
      "status" : 409,
      "message" : "The target deployment path 'org/example/gradle/publishing/sample-plugin-publish/1.0.0-SNAPSHOT/sample-plugin-publish-1.0.0-20231121.103222-1.pom' does not match the POM's expected path prefix 'greeting/greeting.gradle.plugin/1.0.0-SNAPSHOT'. Please verify your POM content for correctness and make sure the source path is a valid Maven repository root path."
    } ]
  }

It looks like POM descriptor for the plugin library is not computed properly: POM details are taken from the plugin marker artefact, the coordinates are not the expected ones.

Reproduction steps

Example of project setup to reproduce the error:

/src/main/java/org/gradle/sample/plugin/GreetingPlugin.java

package org.gradle.sample.plugin;

import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class GreetingPlugin implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        project.getLogger().quiet("applying greeting plugin");

        project.getTasks().register("hello", task -> {
            task.doLast(t -> {
                project.getLogger().quiet(" Hi Bob!");
            });
        });
    }
}

Expected behavior

The Artifactory plugin should publish all expected artefacts and/or corresponding POM descriptors without error.

Artifactory Gradle plugin version

5.1.11

Operating system type and version

Windows 11

JFrog Artifactory version

7.49.10

Gradle version

8.4

mricciuti commented 8 months ago

I guess the issue comes from this: https://github.com/jfrog/artifactory-gradle-plugin/pull/82/files#diff-4ce16214779b229631529a9e909aae5d4c4a3b1b6d8aff171f9705228936e42dR67

in case of multiple maven publications in the same gradle project: this "findFirst(..) will make POM coordinates resolution for each publication fail .

JosephWitthuhnTR commented 7 months ago

Problem looks to be broader/more generic than just Gradle plug-ins. We have a different build that publishes multiple publications/POM files/artifacts, and we are having the same problem (it crosses the wrong Maven POM coordinates with the wrong publications).

tinca commented 7 months ago

In a multi-module project where modules publish their artifacts, we see for xx module:

> Task :artifactoryDeploy
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':xx:artifactoryPublish'.
> Cannot collect deploy details for :xx:artifactoryPublish

module and pom files have been published, the jar was missing This happens with Gradle 8.1.1. Downgrading artifactory plugin to 5.1.10 restores the correct behavior.

bmeier-pros commented 7 months ago

Verified that this is affecting our publications as well, we are reverting to 5.1.10 until this is fixed.

yahavi commented 7 months ago

@tinca @mricciuti @JosephWitthuhnTR @bmeier-pros Thanks for reporting this issue! We created https://github.com/jfrog/artifactory-gradle-plugin/pull/88 to fix it. We'll keep you updated.

yahavi commented 7 months ago

@tinca @mricciuti @JosephWitthuhnTR @bmeier-pros Gradle Artifactory plugin 5.1.12 has been released. This version includes the fix for this issue. We'd appreciate your feedback on that.

tinca commented 7 months ago

Thanks for the quick fix (have not checked yet)!

mricciuti commented 7 months ago

Hi @yahavi , I have tested my scenario with this new version, it does fix the issue with Gradle plugins publication. I have not checked other cases reported on this issue ,but I guess these should be fixed as well.

Thanks !

JosephWitthuhnTR commented 7 months ago

This fixed our use case as well. Thanks!

bmeier-pros commented 7 months ago

Hi @yahavi, I have also verified our use case is resolved. Thank you!