I've found a way to use kythe for java gradle built projects, do you have any advice?

212 views
Skip to first unread message

zhouya...@gmail.com

unread,
Dec 24, 2015, 2:29:53 AM12/24/15
to Kythe
Kythe extract maven built java projects by setting these parameters:
maven.compiler.forceJavacCompilerUse=true
maven.compiler.fork=true
maven.compiler.executable=/opt/kythe/extractors/javac-wrapper.sh
So, if i could set these parameters in gradle, i would use kythe for gradle built projects.

I found gradle has CompileOptions, which has fork parameter, and ForkOptions, which has executable parameter. I modify these parameters like maven project by changing project's build.gradle file, and it works. 
But i have to modify every project's build.gradle file if i want to use kythe for it. So I pull gradle source, build a gradle with these parameters set for using kythe, and it works for some projects, like spring-framework, spring-security and so on. 
Am i in the right way? Do you have any advice on supporting kythe for gradle built projects, to "help the ease of use for Kythe and increase the breadth of what it can index" like you said?

Thank you.

Yucong Sun

unread,
Dec 25, 2015, 10:29:45 PM12/25/15
to zhouya...@gmail.com, Kythe
Ping?

Has anyone had success making gradle use javac-wrapper.sh ?

Cheers
> --
> You received this message because you are subscribed to the Google Groups
> "Kythe" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kythe+un...@googlegroups.com.
> To post to this group, send email to ky...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/kythe/b612f46f-aada-45b5-ae46-887e7d95feb6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Juan Chen

unread,
Jan 4, 2016, 12:37:26 PM1/4/16
to Yucong Sun, zhouya...@gmail.com, Kythe
I have used javac-wrapper with Java projects built with gradle, by appending to build.gradle:

allprojects {
  gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
      options.fork = true
      options.forkOptions.executable = '/opt/kythe/extractors/javac-wrapper.sh'
    }
  }
}

And then building the projects with gradlew or gradle as usual (with REAL_JAVAC, KYTHE_ROOT_DIRECTORY, and KYTHE_OUTPUT_DIRECTORY set properly).


Yucong Sun

unread,
Jan 5, 2016, 1:36:55 AM1/5/16
to Juan Chen, zhouya...@gmail.com, Kythe
Instead of modifying build.gradle, we are trying to look for a way to
hijack javac in JDK instead.

So far we had success inserting a thing in com.sun.tools.javac.Main .
That worked for Maven, but gradle seems to be using
com.sun.tools.javac.api.JavacTool or com.sun.tools.javac.main.Main ..
we are getting lost in all the variations and still trying to figure
our way out.

Any help would be appreciated!

Omer Kareem

unread,
Jun 1, 2017, 5:10:54 PM6/1/17
to Kythe, jua...@google.com, zhouya...@gmail.com, suny...@gmail.com
Hi,

Was wondering if you guys had any update towards a working solution of using gradle with Kythe.

Thanks!
Message has been deleted

Robin Palotai

unread,
Jun 24, 2021, 1:57:51 AM6/24/21
to Slavko Glisic, Kythe
Hi guys,

Not sure about your approach, but I successfully used kythe with Gradle in the past. Part of the solution was taking the existing javac wrapper script, and making Gradle believe that is javac.

No need to hack on the Java level, just fork out calling both kythe and the real javac from that wrapper.

Slight complications:
- I needed a small Gradle function injected to all builds, to generate a custom vname mapping, so names match up when generate from sources, jars etc.

- Lombok, or generally any source-transforming plugin would need to be run by kythe. There's no exposed way to do this, but a fairly simple local hack is described in some GH issue I think.

Good luck,
Robin

On Mon, Jun 21, 2021, 06:07 Slavko Glisic <sla...@glisic.com> wrote:
Hi all,

I tried to follow along with Gradle and Java 8, however, always getting the same error:
EXTRACT ERR: Error: A JNI error has occurred, please check your installation and try again
EXTRACT ERR: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/main/Option
EXTRACT ERR:    at java.lang.Class.getDeclaredMethods0(Native Method)
EXTRACT ERR:    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
EXTRACT ERR:    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
EXTRACT ERR:    at java.lang.Class.getMethod0(Class.java:3018)
EXTRACT ERR:    at java.lang.Class.getMethod(Class.java:1784)
EXTRACT ERR:    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
EXTRACT ERR:    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
EXTRACT ERR: Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.main.Option
EXTRACT ERR:    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
EXTRACT ERR:    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
EXTRACT ERR:    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
EXTRACT ERR:    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
EXTRACT ERR:    ... 7 more


Shahms King

unread,
Jul 8, 2021, 1:44:14 PM7/8/21
to Robin Palotai, Slavko Glisic, Kythe
Were you able to get this working?

The error suggests you're running against a Java runtime which lacks the java tools jar (although I can't recall off hand when that happens; it might need to run against a JDK and not just a JRE installation).

Can you include the result of `which java`, JAVA_HOME, etc.?

Thanks,
--Shahms

Reply all
Reply to author
Forward
0 new messages