GWT compilation is skipped in maven when modular packaging - pom

I am trying to reuse compiled gwt compilation in another war. To do this, I am trying to modify the existing maven module packaging from war to pom . Then I plan to use the maven-assembly-plugin to zip the js gwt module and use it later in another military module.

I tried changing the packaging tag from <packaging>war</packaging> to <packaging>pom</packaging> in pom.xml from the Verification Example . gwt-maven-plugin is never included in compilation. Instead, it skips compilation !!!!!

  • What is happening?
  • Is this expected?
  • Is there any workaround?

enter image description here

+4
source share
2 answers

To combine multiple compiled gwt modules into a single .war file using maven-dependency-plugin

  • Put all your gwt examples as familiar (.war) and install them mvn install or mvn deploy if you have a private maven repo.
  • Create an empty maven module of type war , without code, but with the maven folder structure, you can add any additional material you need as global src/main/webapp/index.html .
  • Configure the new module to use the maven-dependency-plugin , as shown below, and run the mvn package :

     <dependency> <groupId>my.group</groupId> <artifactId>example1</artifactId> <version>...</version> <type>war</type> </dependency> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>unpack-gwt-examples</id> <phase>prepare-package</phase> <goals> <goal>unpack-dependencies</goal> </goals> <configuration> <includeGroupIds>my.group</includeGroupIds> <includes>**/example1/**</includes> <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}</outputDirectory> </configuration> </execution> </executions> </plugin> 

Finally, associated with the gwt-maven-plugin, as with any other maven connection, it would be enough to select the appropriate pom packaging life cycle phase (package, install or deploy):

  ... <packaging>pom</packaging> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> ... <configuration> ... </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> 

Unfortunately, gwt-maven-plugin specifically prohibits compilation when the packaging is pom, see line # 269 of CompileMojo.java

+3
source

You can create reusable modules (which you mention as samples in the comments) as separate GWT projects without EntryPoint. Put them as jar and add the following as resources :

  • client side source code
  • other resource elements that will be needed for the final compilation (images, xml files, etc.).

Something like that:

 <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> ... </plugin> </plugins> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/services/**</include> <include>**/client/**</include> <include>**/public/**</include> <include>**/*.gwt.xml</include> </includes> </resource> </resources> </build> 

To do this, you can reuse it in any other GWT project. When you do this, you just need to add the dependency (to the reusable module) in pom.xml and import in *.gwt.xml .

As for Maven's behavior, this seems correct. pom packaging goes through the phases of package , install and deploy and

By default, the compilation target is configured to run during the prepare-package phase to run as late as possible.

You can change the phase in the execution of the plugin, but I think it is dangerous, because you cannot know when exactly at the package stage your code will be compiled.

+1
source

All Articles