jfrog / artifactory-gradle-plugin

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

Unable to apply com.jfrog.artifactory plugin in a build-logic included build gradle.kts precompiled build script #96

Closed maksym-moroz closed 6 months ago

maksym-moroz commented 6 months ago

Describe the bug

Specifying the dependency in a root-level build.gradle.kts with a version directly or via version catalog and not applying it but instead opting to apply it inside build-logic convention plugin produces the following error log

* Where:
Precompiled script plugin '***/build-logic/src/main/kotlin/artifactory-publishing.gradle.kts' line: 1

* What went wrong:
Plugin [id: 'com.jfrog.artifactory'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)

Current behavior

Unable to apply com.jfrog.artifactory plugin to lift out the publishing logic into a convention plugin

Reproduction steps

No response

Expected behavior

Being able to set up publishing from a convention plugin inside an included build

Artifactory Gradle plugin version

5.1.13 or any

Operating system type and version

MacOS

JFrog Artifactory version

No response

Gradle version

8.2.0

yahavi commented 6 months ago

@maksym-moroz Appreciate you flagging this problem! Could you please share a basic reproducer project? Just a small GitHub project that we can fork to replicate the issue. Thanks!

maksym-moroz commented 6 months ago

For those interested in extracting jfrog-artifactory setup into a precompiled convention plugin, here is the quick guide.

To apply jfrog-artifactory inside your convention plugin you first need to satisfy the dependency on it inside build.gradle.kts for your included build

dependencies {
    implementation(libs.jfrog.artifactory)
}

This is where I faced the problem since applying a plugin via implementation is not allowed. Here is the Gradle spec for addressing this problem, however it's not done yet but there is a workaround described, copying it here in case the link dies:

It is currently not possible to use the plugin id (and version) or the version catalog for dependency declaration, which means the required coordinates have to be known or be derived somehow. The steps to retrieve the coordinates are manual and cumbersome: One has to lookup the plugin on the Plugin Portal, find the coordinates in the legacy snippet at the bottom and copy them from there.

For jfrog-artifactory legacy path is org.jfrog.buildinfo:build-info-extractor-gradle

Adding this as a library to the version catalog and then referring to it from build.gradle.kts dependencies block allows you to add id("com.jfrog.artifactory") to your precompiled convention plugin.

For some reason using artifactory {} block is not possible as it keeps getting unrecognised after getting generated. For those wondering how to configure it in case you face the same issue, extension is called ArtifactoryPluginConvention, i.e. configure<ArtifactoryPluginConvention> {...}

Hope this helps.

yahavi commented 6 months ago

Thank you very much for your guidance, @maksym-moroz! It will certainly be beneficial to others who encounter this issue.