# Apply a gradle plugin (errorprone) from a custom Gradle Java plugin

**URL:** <https://discuss.gradle.org/t/apply-a-gradle-plugin-errorprone-from-a-custom-gradle-java-plugin/34645>\
**Category:** Help/Discuss\
**Created:** [January 23, 2020, 9:25am UTC](https://discuss.gradle.org/t/apply-a-gradle-plugin-errorprone-from-a-custom-gradle-java-plugin/34645 "2020-01-23T09:25:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matans](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@matans](https://discuss.gradle.org/u/matans)\
**Post date:** [January 23, 2020, 9:25am UTC](https://discuss.gradle.org/t/apply-a-gradle-plugin-errorprone-from-a-custom-gradle-java-plugin/34645/1 "2020-01-23T09:25:27Z")

</div>

need to apply a gradle plugin, in this case errorprone from a custom Gradle plugin.

My Plugin has a build.gradle that looks like this:

```
gradlePlugin {
    plugins {
        myErrorprone {
            id = 'my-errorprone'
            implementationClass = 'com.my.MyErrorpronePlugin'
        }
    }
}

```

And the plugin code is:

```
public class MyErrorpronePlugin implements Plugin<Project> {
  List<String> compilerArgs =
  Arrays.asList(
      "-XepExcludedPaths:.*/proto/.*|.*/protoGeneratedSrc/.*",
      "-XepDisableWarningsInGeneratedCode");

  @Override
  public void apply(Project project) {
project.getPluginManager().apply("net.ltgt.errorprone:");
for (JavaCompile task : project.getTasks().withType(JavaCompile.class)) {
  task.getOptions().setCompilerArgs(compilerArgs);
}
  }
}

```

Then, when in another project I apply this plugin (after getting the dependencies in the buildscript) like this:

`apply plugin: 'my-errorprone'`

```
A problem occurred evaluating root project 'my-project.
Failed to apply plugin [id 'my-errorprone'] Plugin with id 'net.ltgt.errorprone' not found.

```

And it only resolved if i add to buildscript classpath

`classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.16"`

How can I make my plugin work in such way that the project that consumes my plugin will not have to add this direct dependency in the classpath in “net.ltgt.gradle:gradle-errorprone-plugin:0.0.16” ?

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [January 23, 2020, 5:35pm UTC](https://discuss.gradle.org/t/apply-a-gradle-plugin-errorprone-from-a-custom-gradle-java-plugin/34645/2 "2020-01-23T17:35:54Z")

</div>

I suggest that you apply the plugin by class rather than by ID. This will force you to include the error prone dependency in your plugin’s dependency list as it won’t compile until you add the dependency

Eg:

```gradle
import net.ltgt.gradle.errorprone.ErrorPronePlugin.class;

public class MyPlugin implements Plugin<Project> {
   public void apply(Project project) {
       project.getPluginManager().apply(ErrorPronePlugin.class);
       // custom logic here 
   } 
} 

```

---

<div class="post-metadata">

**Author:** ![matans](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@matans](https://discuss.gradle.org/u/matans)\
**Post date:** [January 23, 2020, 9:54pm UTC](https://discuss.gradle.org/t/apply-a-gradle-plugin-errorprone-from-a-custom-gradle-java-plugin/34645/3 "2020-01-23T21:54:30Z")

</div>

Hey Lance, Thanks a lot!!  
I understand the idea behind it,and i think it will work, but i am not sure what I should add to my custom plugin build.gradle file.  
I tried few things non of them seemed to work.

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [January 24, 2020, 7:14am UTC](https://discuss.gradle.org/t/apply-a-gradle-plugin-errorprone-from-a-custom-gradle-java-plugin/34645/4 "2020-01-24T07:14:40Z")

</div>

Something like

```gradle
repositories {
   maven {
      url "https://plugins.gradle.org/m2/"
   }
} 
dependencies {
   api "net.ltgt.gradle:gradle-errorprone-plugin:1.1.1"
} 

```
