Replies: 1 comment 5 replies
-
Broadly speaking: not supported in the same way. With that said, you didn't actually get to the important part in your example code - how do you write a single codebase that depends on Logger.java, then use it in both a Java application and a j2cl application? The bazel answer is that you make two projects, one which depends on logger-j2cl, and one which depends on logger - they aren't the same project, they just happen to use the same sources. Then, the j2cl application depends on the j2cl library, which depends on j2cl logger, and the java application depends on the java library, which depends on the java logger. There is no shared code at all, just shared source files that happen to be compiled twice, by parallel and totally unrelated/distinct projects. You can do that in maven! But it won't really seem very maven-ish. That's your decision though - even in bazel if you had a moderately large codebase with several modules and hundreds of classes between them, maintaining two parallel dependencies trees might get irritating - or maybe not. I notice you aren't actually using bazel (as you're here in the j2cl maven plugin's discussion), so maybe the bazel way isn't so great either. There is another way that works most of the time - since you already own both copies of Logger.java (as it is clearly in your sources, in the example), you can use the
The real method instantiates the JRE impl and calls it - you could also just keep a singleton depending on if you're holding state, etc. The JreImpl has decorated all of its members as being incompatible with j2cl/gwt, so j2cl pretends they aren't there, and relies on the members in the supertype. This way, the JRE gets to call its methods, and the JS env only calls code it is compatible with. This isn't always perfect, as you might end up with trouble with further upstream dependencies - but the approach will save you (in both bazel and maven) from needing to duplicate the dependency hierarchy. |
Beta Was this translation helpful? Give feedback.
-
Super sourcing in Bazel, this looks like this according to the example here (https://github.com/google/j2cl/blob/master/docs/best-practices.md#super-sourcing-writing-platform-specific-code):
How would this look with j2clmavenplugin?
My current plugin configuration looks like so:
Beta Was this translation helpful? Give feedback.
All reactions