Calvin Taylor
Calvin Taylor

Reputation: 694

gradle init script can't apply artifactory plugin

I'm trying to offload build logic into a gradle init script, which gets included in a custom gradle wrapper. It seems promising. One of the things I need to do is to apply the artifactory plugin prior to configuring it, while the following code works fine in build.gradle, it fails to find the plugin when the code is shifted into an init script.

build.gradle:

buildscript{

    Properties properties = new Properties()
    properties.load(new File(gradle.getGradleUserHomeDir(), 'gradle.properties').newDataInputStream())

    repositories {
        maven {
            url properties.artifactory_contextUrl + '/gradle-plugins-virtual'
            credentials {
                username = properties.artifactory_user
                password = properties.artifactory_password
            }
        }
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2"
    }
}
apply plugin: "com.jfrog.artifactory"

and in the init script it's almost the same:

initscript{

    Properties properties = new Properties()
    properties.load(new File(getGradleUserHomeDir(), 'gradle.properties').newDataInputStream())

    repositories {
        maven {
            url properties.artifactory_contextUrl + '/gradle-plugins-virtual'
            credentials {
                username = properties.artifactory_user
                password = properties.artifactory_password
            }
        }
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2"
    }
}

apply plugin: "com.jfrog.artifactory"

but I get Plugin with id 'com.jfrog.artifactory' not found. with this attempt.

I have also tried making an init plugin, but my plugin skills are not strong, and it also seems to fail.

I tried moving just the apply plugin line to build.gradle from the init script but that also fails, indicating it might be the dependency resolution. How can I debug this further?

I did a build scan and it appears that the plugin jar was found okay.

org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2

commons-io:commons-io:2.7
commons-lang:commons-lang:2.4
commons-logging:commons-logging:1.1.1
  
1.2
org.apache.ivy:ivy:2.2.0
org.jfrog.buildinfo:build-info-extractor:2.19.2

Any help, comments, suggestions appreciated.

Rant: gradle docs have far too few examples.

Upvotes: 1

Views: 1017

Answers (1)

Huu Phuong Vu
Huu Phuong Vu

Reputation: 1074

For gradle init script, you must use the fully qualified class name of the plugin instead of the id. Like this:

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

Upvotes: 3

Related Questions