Java – can I force GWT compilation without an entry point? (verify compatibility with GWT)

This question is related to this question, but not repeated

My question is slightly different; I have a "utility module" that is shared between client and server code and does not contain GWT specific code

I understand that usually, all resources are dragged into a specific project and everything is compiled together But there is a problem: when I compile the main project, I only know whether my utility project is "GWT compatible" It's too late; I haven't even started the main project, but I want to know that my utility project is "GWT compatible" before I "submit" to my SCM

In other words, I want to verify the GWT compatibility of the utility project, independent of its use in a separate project (module)

GWT does not cover a large part of JRE, and it is particularly possible to use non GWT compatible classes or methods in utility modules This is what I want to verify

Editor: I think I can add a "virtual entry point", but this makes the project dependent on GWT. I don't want to do this because it is "common" code and can also be used by those who don't use GWT If important, I use Maven as the build system

Edit2: no matter what I do, I will only get real compilation / validation through the entry point (I don't need to reference any classes) Neither < force > true < / force >, nor < failonerror > true < / failonerror > will do it Is there a way to define this entry point for shared projects that only GWT Maven plugin can see instead of javac (to avoid adding unnecessary dependencies to Java code)?

Solution

The compiler actually always accesses all the code on the source path (Note: it is not exactly the same as the classpath), starts with the requested module, uses any < source > tag, and then checks each < inherits > along the way If it finds some incompatible or non compilable content, it marks it as corrupted and moves on – as long as there is actually no content dependent on it (that is, entrypoint, or what entrypoint depends on), you will only see this message:

Validating newly compiled units
      Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.

If you include the - strict flag, the compilation will actually fail when it encounters something that cannot be included correctly

This work is done in the initial stage of compilation, and typeoracle for the generator is constructed long before any JS is built That type of Oracle is passed to the generator, and they need to be able to ask questions such as "which interfaces on the source path have JSO implementation" and "all possible subclasses of list" The generator can perform a number of operations, including issuing more types, then parsing and compiling them, and the process will continue until a complete jpgram of all possible types is created based on the current module set

The jpgram is then compiled based on what is fundamentally attainable - entry points and some other details (such as how to simulate Java details such as casts, arrays, long integers, exceptions, etc.)

If - strict is not specified, and the compiler finally needs to reach the content that cannot be accessed due to early compilation problems, that is when you find it Using - strict to stop early will help ensure that you find these problems faster

Another interesting fact: by default, use COM. Com in the module google. gwt. user. User (or any other < inherits >) that depends on it, you already have an entry point, or several! These can quickly check that your page is working, such as using a strict DOCTYPE, or the browser actually matches the expected user Agent settings This means that modules can usually be compiled even if there is no entry point (except GWT Maven plugin: compile, which does not only consider those built-in modules for compilation)

Editor: OK, there's even one: from http://www.gwtproject.org/doc/latest/DevGuideCompilingAndDebugging.html At first, combined with - strict, it seems that you can force validation to run without actually compiling into JS:

-validateOnly            Validate all source code,but do not compile
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>