# Applying plugins from external script

**URL:** <https://discuss.gradle.org/t/applying-plugins-from-external-script/20308>\
**Category:** Help/Discuss\
**Created:** [November 3, 2016, 10:13am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308 "2016-11-03T10:13:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sathyakumar](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Sathyakumar](https://discuss.gradle.org/u/Sathyakumar)\
**Post date:** [November 3, 2016, 10:14am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/1 "2016-11-03T10:14:00Z")

</div>

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](https://discuss.gradle.org/t/how-do-i-apply-a-plugin-to-a-project-from-a-shared-applied-gradle-file/7508/6).

My artifactory.gradle looks like  
buildscript {  
repositories {  
maven {  
url “[https://plugins.gradle.org/m2](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.

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [November 3, 2016, 10:36am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/2 "2016-11-03T10:36:49Z")

</div>

You didn’t add the dependency to the plugin. So far you only have the repository. See the instructions on the [plugin portal](https://plugins.gradle.org/plugin/com.jfrog.artifactory).

---

<div class="post-metadata">

**Author:** ![Sathyakumar](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Sathyakumar](https://discuss.gradle.org/u/Sathyakumar)\
**Post date:** [November 3, 2016, 11:06am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/3 "2016-11-03T11:06:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [November 3, 2016, 11:11am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/4 "2016-11-03T11:11:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sathyakumar](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Sathyakumar](https://discuss.gradle.org/u/Sathyakumar)\
**Post date:** [November 3, 2016, 11:33am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/5 "2016-11-03T11:33:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sathyakumar](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Sathyakumar](https://discuss.gradle.org/u/Sathyakumar)\
**Post date:** [November 3, 2016, 11:41am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/6 "2016-11-03T11:41:20Z")

</div>

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'
```

---

<div class="post-metadata">

**Author:** ![Sathyakumar](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Sathyakumar](https://discuss.gradle.org/u/Sathyakumar)\
**Post date:** [November 3, 2016, 11:50am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/7 "2016-11-03T11:50:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [November 3, 2016, 11:59am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/8 "2016-11-03T11:59:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sathyakumar](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Sathyakumar](https://discuss.gradle.org/u/Sathyakumar)\
**Post date:** [November 4, 2016, 4:15am UTC](https://discuss.gradle.org/t/applying-plugins-from-external-script/20308/9 "2016-11-04T04:15:14Z")

</div>

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