1
votes

I'm trying to DRY some of the JFrog publishing code from my build.gradle to an external file (the Gradle Script plugin) (which I was duplicating in different Gradle projects).

https://github.com/wizpanda/gradle-common/blob/06a497b62fb4bb86facd96375bad1d91a67545d1/grails-plugin-jfrog-publish.gradle

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0"
    }
}

apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

publishing {
    publications {
        wpJFrogMaven(MavenPublication) {

            // Code removed for brevity 

        }
    }
}

// Code removed for brevity

I'm using this Gradle script plugin at the end of my main build.gradle of my actual project-

apply from: "https://raw.githubusercontent.com/wizpanda/gradle-common/main/grails-plugin-jfrog-publish.gradle"

When I run any Gradle task like- ./gradlew artifactoryPublish, it fails with the error-

FAILURE: Build failed with an exception.

* Where:
Script 'https://raw.githubusercontent.com/wizpanda/gradle-common/06a497b62fb4bb86facd96375bad1d91a67545d1/grails-plugin-jfrog-publish.gradle' line: 14

* What went wrong:
A problem occurred evaluating script.
> Plugin with id 'com.jfrog.artifactory' not found.

But if I define the same buildscript configuration and plugins in the main build.gradle file of the project, it works fine.

I already spent 3-4 hours debugging it and read various articles, blogs and documentations-

Any stupid thing am I missing?

2

2 Answers

3
votes

Unfortunately third party plugins can not be transitively applied in the external Gradle script plugin if you reference it by ID.

You will have to reference the plugin by the implementation-class instead.

There is an open ticket regarding this issue.

You can see necessary changes in following PR.

apply plugin: 'com.jfrog.artifactory'

into

apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
1
votes

Apply by id is not supported inside external build script. An alternative:

apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin

Plugin properties