Compile code in CompileTask?

Answered

Hi,

I know CompileTask is supposed to be used to run things before and after the actual compilation phase, but we'd like to reuse the Ceylon analyzer, which is kind of slow to be initialized, to compile Ceylon code directly from a CompileTask. This analyzer is already used to show errors in the editor, to resolve declarations etc. so it's very important for us to be able to reuse it to compile code in the same process as the IDE.

Do you think this could cause problems, as the new compilation API is entirely designed to be run in a separate process?

Bonus question: in mixed Ceylon/Java projects, the Ceylon compiler is also able to compile Java code, so if we decide to run it in a CompileTask, is there a way to tell IntelliJ that the Java files we just compiled don't need to be compiled again in the external process?

Thanks for your help.

Bastien

1
2 comments
Official comment

Hi Bastien,

yes, you can compile code in CompileTask in the same process as the IDE. It's preferable to run compilation processes in a separate process because they are usually consume a lot of CPU and memory resources, and it's better if this doesn't slow down the IDE. However if you have good reasons to run the compilation in the IDE process you can do that.

In order to switch off the default Java compilation you can provide an implementation of com.intellij.compiler.impl.javaCompiler.BackendCompiler extension (look at org.jetbrains.plugins.groovy.compiler.GreclipseIdeaCompiler from Groovy plugin for example). This will add a new variant to 'Use compiler' combobox in File | Settings | Build, Execution, Deployment | Compiler | Java Compiler. If this variant is selected the external build process won't compile java files. You can also set the option programmatically via com.intellij.compiler.CompilerConfigurationImpl#setDefaultCompiler method. Note that this option will affect the whole project. 

Thanks Nikolay!
0

Please sign in to leave a comment.