# Using javac plugins with PlatformScalaCompile

**URL:** <https://discuss.gradle.org/t/using-javac-plugins-with-platformscalacompile/26562>\
**Category:** Help/Discuss\
**Created:** [April 9, 2018, 9:08pm UTC](https://discuss.gradle.org/t/using-javac-plugins-with-platformscalacompile/26562 "2018-04-09T21:08:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbarkley](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@bbarkley](https://discuss.gradle.org/u/bbarkley)\
**Post date:** [April 9, 2018, 9:08pm UTC](https://discuss.gradle.org/t/using-javac-plugins-with-platformscalacompile/26562/1 "2018-04-09T21:08:00Z")

</div>

I’m trying to use a javac plugin with a Play project but am not able to get the compiler to find the plugin. Everything works find when running javac from the command line, so the issue doesn’t seem to be with the plugin or a missing `META-INF/services/com.sun.source.util.Plugin` file.

In `build.gradle` I’ve added  
`tasks.withType(PlatformScalaCompile).all { task -> task.options.compilerArgs += ["-Xplugin:CustomPlugin"] }`

During compilation I get  
`> Task :play-plugin-project:compilePlayBinaryScala plug-in not found: CustomPlugin`

Currently the javac plugin is part of another Gradle plugin, and the class can be found on the classpath using `classloader.loadClass`. I’ve also tried adding `-cp` with compilerArgs, and setting fork to true and adding `-cp` to the `forkOptions.jvmArgs`. I still get the plug-in not found error.

What’s the correct way to set up the PlatformScalaCompile so that javac is able to find my plugin?

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [April 11, 2018, 8:54pm UTC](https://discuss.gradle.org/t/using-javac-plugins-with-platformscalacompile/26562/2 "2018-04-11T20:54:30Z")

</div>

Hi @bbarkley,

I think we greatly restrict the classpath that the Scala compiler uses. Is the javac plugin intended for the Scala compiler _and_ javac or just javac if the Scala compiler invokes it? Is this something you’re already doing via sbt?

---

<div class="post-metadata">

**Author:** ![bbarkley](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@bbarkley](https://discuss.gradle.org/u/bbarkley)\
**Post date:** [April 11, 2018, 8:57pm UTC](https://discuss.gradle.org/t/using-javac-plugins-with-platformscalacompile/26562/3 "2018-04-11T20:57:16Z")

</div>

It’s only to be used by javac if the Scala compiler invokes it, though we’ll probably be applying it to normal Java compilation for non Play projects as well. It’s not something that we’ve done with sbt before.

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [April 11, 2018, 11:24pm UTC](https://discuss.gradle.org/t/using-javac-plugins-with-platformscalacompile/26562/4 "2018-04-11T23:24:09Z")

</div>

OK.

If you’re compiling your Java sources with a `PlatformJavaCompile` or `JavaCompile` task, I think you can add your javac plugin to the [`annotationProcessor` configuration](https://docs.gradle.org/current/release-notes.html#convenient-declaration-of-annotation-processor-dependencies) and pass the extra compiler arguments as you’re doing above. javac compiler plugins appear to get their classpath from the [annotation processor classpath](https://docs.oracle.com/javase/8/docs/jdk/api/javac/tree/com/sun/source/util/Plugin.html).

For `javac` called from the Scala compiler, it seems harder. I don’t see a great way to properly feed everything through (Gradle -\> Zinc Scala compiler -\> javac).

---

<div class="post-metadata">

**Author:** ![bbarkley](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@bbarkley](https://discuss.gradle.org/u/bbarkley)\
**Post date:** [April 12, 2018, 7:07pm UTC](https://discuss.gradle.org/t/using-javac-plugins-with-platformscalacompile/26562/5 "2018-04-12T19:07:09Z")

</div>

Is there a less-than-great way? 😛 Do you have any pointers for where the classpath the handoff is made in the chain between Gradle-\>Zinc-\>javac?
