简体   繁体   中英

Could I use Java 6 Annotation Processors / JSR 269 to produce code for GWT in Maven?

Since GWT works strictly on Java source code, and Annotation Processors / JSR 269 generate also Java source code, would there be a way, in Maven , to have javac process the files, using the Annotation Processors, and save the generated Java source code somewhere, such that GWT can then use it itself, saving the work of reproducing the Annotation Processors implementation in a GWT generator ?

According to this question , assuming the answer is still relevant, it would be best to use the maven-processor-plugin to process annotations. The documentations says that you can specify an "outputDirectory". And this question says you should use the copy-resources goal of the maven-resources-plugin to make the source available to GWT.

Assuming all of this is right, my question is: how do you tell Maven, that it should compile the code with javac, and run the other (maven-processor-plugin / maven-resources-plugin) plugins before running the "GWT Maven Plugin" ? (Or would that always, for some reason, happen in that order anyway?)

There are many ways to configure your Maven build. Here are a few of them:

  • let the maven-compiler-plugin handle Java compilation and annotation processing, and configure it to output the generated sources in addition to compiling them. Then use the build-helper-maven-plugin to add the generated sources directory to the project sources (or resources) for later consumption by the gwt-maven-plugin. That means the build-helper-maven-plugin has to run between the compile and prepare-package phases.

  • use the maven-processor-plugin to run the annotation processors and output the generated sources, and make sure they're added to the project sources . Then disable annotation processing for the maven-compiler-plugin using <proc>none</proc> .

  • use the maven-compiler-plugin twice: once to run the annotation processors (with <proc>only</proc> ), and once to compile the files (with <proc>none</proc> ). Basically, the first execution is equivalent to using the maven-processor-plugin.

You shouldn't need to use resources:copy-resources .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM