Applying plugins from external script

Using version 3.1, I decided to split my build file with one file dedicated to pushing artifacts to artifactory. I created a new file artifactory.gradle and applying it from the main build file.

Am facing issues when I try to apply from: 'gradle-common/artifactory.gradle'. I understand that there is a known problem as described here.

My artifactory.gradle looks like
buildscript {
repositories {
maven {
url “https://plugins.gradle.org/m2
}
}
}
apply plugin: org.jfrog.hudson.ArtifactoryPlugin
apply plugin: org.gradle.api.plugins.MavenPlugin

And I am getting an error
* Where:
Script ‘/Users/sseshac/src/JenkinsTrial/src/repo/gradle-common/artifactory.gradle’ line: 8

* What went wrong:
A problem occurred evaluating script.
> Could not get unknown property 'org' for root project 'api' of type org.gradle.api.Project.

Any help will be greatly appreciated.

You didn’t add the dependency to the plugin. So far you only have the repository. See the instructions on the plugin portal.

What would the dependency be for a core plugin like maven-publish ?

You don’t need a dependency for core plugins, they are already on the classpath. I thought the failure was because of the artifactory plugin.

Jumped the gun wrt core plugin.

But this is so inconvenient. I just am not able to locate the actual plugin class of artifactory plugin (The one I was using was a wrong plugin class). The source code of the plugin does not seem to be available anywhere, (So will be the case for numerous other plugin I suppose). I really hope Gradle team solves this known problem.

Any idea where the buildScript dependencies are downloaded ? So I can view the jar file and find out the class to use.

Somehow managed to find the plugin class. Now getting this error

* Where:
Script '/Users/sseshac/src/JenkinsTrial/src/repo/gradle-common/artifactory.gradle' line: 11

* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin [class 'org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin']
   > Cannot cast object 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention@3676cb79' with class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention' to class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention'

Apparently I had two plugin definitions for artifactory that caused the issue. Removing it from the main build.gradle made that error go away, but newer errors.

Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method publishing() for arguments [artifactory_c6jal2wkvlz8vpzljcferxcwm$_run_closure1@57575bf] on root project 'api' of type org.gradle.api.Project.
        at org.gradle.internal.metaobject.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:182)
        at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:167)

This even though I have applied Maven plugin within artifactory.gradle.
apply plugin: org.gradle.api.plugins.MavenPlugin
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin

Error goes away when I do include maven-publish in my main build.gradle
plugins {
//id “com.jfrog.artifactory” version "4.0.0"
id "java"
id “maven-publish”
}

Am beginning to think, this was a bad idea to split build files this way and probably useful only when you have pure methods that you want to re-use in gradle files.

For Gradle core plugins you can just use their id. You script plugin is currently using the old maven plugin. You need to use maven-publish instead.

Thanks. that worked. I wish this workaround for a known issue is documented somewhere (or may be it is already)