Using Lombok with Tycho and Eclipse

760 views
Skip to first unread message

Marcel Bruch

unread,
Jan 9, 2012, 2:53:17 AM1/9/12
to Project Lombok
Hi Lombok-ers,

I'm evaluating whether Lombok's build integration into Tycho and its
support for the eclipse compiler exist and is stable (enough) to be
used in one or more eclipse-based projects. A very condensed summary
is available here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=368049

There are a few questions I'd like to ask this list:

Tycho support:
More and more projects at Eclipse build with Tycho. As far as I could
see, delombok seems the only way to use Lombok with Tycho. Is this
correct? I've set up a sample project that uses the delombok approach
but a direct compiler integration would be the preferred solution.
What's the state with this?

Incompatible changes/hooks to eclipse compiler internals:
One committer pointed out that Lombok uses 'dirty' (meaning not
officially supported) ways to get Lombok work with ecf. Is this
correct? It would be dangerous to rely on Lombok if it's going to
break on internal compiler changes.

Thanks for providing more details on these questions.

Best,
Marcel

Reinier Zwitserloot

unread,
Jan 9, 2012, 4:52:25 AM1/9/12
to project...@googlegroups.com
Tycho compiles with ecj, right?

If so, all you need to somehow make happen is that when the tycho plugin fires up ecj, it sneaks this argument onto the JVM bootup parameter list:

-javaagent:lombok.jar

so, i.e.:

java -javaagent:lombok.jar -jar ecj.jar -source 1.6 -target 1.6 -classpath etc etc etc <- these are the args to ecj, not the VM.

then there should be no need to mess with delombok to make tycho work for you. If tycho worked with java, then unless tycho forcibly disables annotation processing the way the play framework does, it should 'just work', no need for strange config.

Unfortunately build tools aren't all that great at allowing you to pass VM parameters when invoking the compiler, so that might be an issue. If push comes to shove, we can contact the tycho team and ask them to add the ability to set VM args, or, failing that, make a tycho fork which is a carbon copy except for allowing you to set VM args some way. I tried googling to see if tycho can do this, but I keep finding pages on how to set the VM args to launch the built end-product, not the VM args for when tycho invokes the compiler during the build process.


Yes, lombok uses unsupported API to hook into ecj. Not as a dirty shortcut, but, there's simply no other way to do what lombok does without doing so. All eclipse releases which were capable of supporting java 1.5 and java 1.6 worked seamlessly, even though we built the original lombok targeted at only one version of eclipse, so while we do rely on private API not changing, that API doesn't, evidently, change very much.

Having said that, with 1.7 support coming up (going off of the info as posted here: http://wiki.eclipse.org/JDT_Core/Java7 ) we'll set up the beta today and see what happens.

delombok exists as an insurance against us (team lombok) failing to keep lombok up to date with any breaking changes to the java language spec or ecj in particular; if for whatever reason lombok is no longer acceptable for use, run your code through delombok and continue with that as your new source base.

Marcel Bruch

unread,
Jan 9, 2012, 10:12:41 AM1/9/12
to project...@googlegroups.com

On 09.01.2012, at 10:52, Reinier Zwitserloot wrote:

> Tycho compiles with ecj, right?

I guess. The compilerid is 'JDT' which makes me think it's ecj.


> If so, all you need to somehow make happen is that when the tycho plugin fires up ecj, it sneaks this argument onto the JVM bootup parameter list:
> -javaagent:lombok.jar

To run lombok as javaagent, (I guess) I've to run the compile goal with fork=true as shown below. Unfortunately, I get:

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.13.0:compile (default-compile) on project org.eclipse.recommenders.lombok: Fatal error compiling: compileoutOfProcess not supported -> [Help 1]

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<fork>true</fork>
<compilerArgument>-javaagent:/Users/Marcel/Downloads/lombok.jar</compilerArgument>
</configuration>
</plugin>


Without fork=true I get:

[INFO] Compiling 2 source files to /Users/Marcel/Workspaces/eclipse.org/lombok-test/target/classes
Unrecognized option : -javaagent:/Users/Marcel/Downloads/lombok.jar

Any idea?


> so, i.e.:
>
> java -javaagent:lombok.jar -jar ecj.jar -source 1.6 -target 1.6 -classpath etc etc etc <- these are the args to ecj, not the VM.
>
> then there should be no need to mess with delombok to make tycho work for you. If tycho worked with java, then unless tycho forcibly disables annotation processing the way the play framework does, it should 'just work', no need for strange config.
>
> Unfortunately build tools aren't all that great at allowing you to pass VM parameters when invoking the compiler, so that might be an issue. If push comes to shove, we can contact the tycho team and ask them to add the ability to set VM args, or, failing that, make a tycho fork which is a carbon copy except for allowing you to set VM args some way. I tried googling to see if tycho can do this, but I keep finding pages on how to set the VM args to launch the built end-product, not the VM args for when tycho invokes the compiler during the build process.

Maybe we should send a request to tycho?

> Yes, lombok uses unsupported API to hook into ecj. Not as a dirty shortcut, but, there's simply no other way to do what lombok does without doing so.

What would be needed to make it 'supported'?

Thanks,
Marcel

Reinier Zwitserloot

unread,
Jan 9, 2012, 11:02:26 AM1/9/12
to project...@googlegroups.com
On Monday, January 9, 2012 4:12:41 PM UTC+1, Marcel Bruch wrote:

I guess. The compilerid is 'JDT' which makes me think it's ecj.



Probably. Write a file with errors in it, then compare the syntax error messages between tycho, ecj, and javac. Should give away what tycho is using internally.
 

To run lombok as javaagent, (I guess) I've to run the compile goal with fork=true as shown below. Unfortunately, I get:


compilerArgument would be an arg to ecj, not to the VM running ecj, so either way that won't work.

I'm assuming you're running tycho from within eclipse, in which case lombok is already present, assuming you've installed it into your eclipse by running lombok.jar as an executable jar. So, lombok should work. If it's not, I'm guessing OSGi is throwing a wrench in the works, but it's something we should be able to fix relatively easily. If you're running tycho as a standalone thing, try passing -javaagent:lombok.jar to the VM that's running tycho.

Maybe we should send a request to tycho?


Given that tycho appears to run ecj inline (something I wasn't expecting it would do, but turns out it's the only thing it will do per your error messages), this isn't something tycho can address.
 

> Yes, lombok uses unsupported API to hook into ecj. Not as a dirty shortcut, but, there's simply no other way to do what lombok does without doing so.

What would be needed to make it 'supported'?

For starters, there would have to be a public API for a java AST, down to the lowest levels (statements and expressions, not just methods and fields which does exist via java.lang.model.*). This does not currently exist. At best ecj could make its own internal ast public API, but as it's kind of a mess I doubt this will be happening anytime soon. That's not the only step, but it's the biggest and most crucial one.

Reply all
Reply to author
Forward
0 new messages