janino-compiler / janino

Janino is a super-small, super-fast Java™ compiler.
http://janino-compiler.github.io/janino
Other
1.25k stars 208 forks source link

Use Janino as compiler in Maven build #158

Closed Thihup closed 2 years ago

Thihup commented 2 years ago

Hi!

Do you know if it would be possible to use Janino as a compiler in a Maven build? I think it would require creating a Maven plugin like so: https://maven.apache.org/plugins/maven-compiler-plugin/non-javac-compilers.html

Using it as a main compiler for my projects (most of them are Maven projects) would be a great way to check for edge cases, and improve the compiler :)

Thihup commented 2 years ago

Source code of Maven plugin for the Jikes compiler: https://github.com/codehaus-plexus/plexus-compiler/blob/master/plexus-compilers/plexus-compiler-jikes/src/main/java/org/codehaus/plexus/compiler/jikes/JikesCompiler.java

aunkrig commented 2 years ago

Hey Thihup,

thank you for your trust in Janino, but I think since it supports the Java 5+ features only partially, it does not make sense to compile "normal" Java programs with Janino.

Also, the strength of Janino is not to compile Java programs "from disk", i.e. read and process all the JRE .class files, but to compile "in memory", with all the already-loaded Java classes. That is what makes it so fast to compile snippets of code.

But maybe it would make sense to do a speed comparison between JAVAC and Janino, like

All but the last should be tremendously faster.

I think such a comparison should make it very clear when and how Janino is useful.

What do you think about it?

Thihup commented 2 years ago

Hey @aunkrig

I think that would be great! :)

Even though it does not support all the Java features, I'd like to give it a try, because currently, we have only Javac and ECJ compilers that are used for compilation but having a new one can be beneficial, as this compiler can do some stuff that other compilers may not want to do.

One example of something that would be great to have implemented in a Java compiler is some of the features the Brian Goetz talks here: https://www.youtube.com/watch?v=iSEjlLFCS3E

So having it as a Maven compiler plugin may attract some other developers that would like to help implement the missing features and maybe be a full compiler as Javac is.

The main goal of this project can still be compiling expressions, but also be used as another implementation of Java compiler too :)

aunkrig commented 2 years ago

Added the performance comparison on the home page:

file:///C:/dev/workspaces/janino/gh-pages/index.html#alternative-compiler-implementations

aunkrig commented 2 years ago

Hey @Thihup,

I looked at https://maven.apache.org/plugins/maven-compiler-plugin/non-javac-compilers.html and https://github.com/codehaus-plexus/plexus-compiler/blob/master/plexus-compilers/plexus-compiler-jikes/src/main/java/org/codehaus/plexus/compiler/jikes/JikesCompiler.java, and it should indeed be simple to write such an adapter, because org.codehaus.commons.compiler.ICompiler is a drop-in replacement for JAVAC.

My question, however, is: When is it useful to have an adapter to a quite limited Java compiler like Janino, other than "check for edge cases, and improve the compiler"? I mean: Who would do that, except you and me?