5

I am trying to reuse a assembled gwt compilation in another war. For this i am try to change the current maven module's packaging from war to pom. I then plan to use maven-assembly-plugin to zip up gwt's module js output and use that later on in another war module.

I tried changing the packaging tag from <packaging>war</packaging> to <packaging>pom</packaging> in pom.xml from Validation sample . gwt-maven-plugin never enters into compilation. Instead, it skips compilation!!!!!

  1. What is happening?
  2. Is this expected?
  3. Is there any workaround?

enter image description here

appbootup
  • 9,537
  • 3
  • 33
  • 65
  • 1
    I dont understand why do you want to change from war to pom? You can produce a .zip after having a .war. I dont follow what you want to do in this second module – Manolo Carrasco Moñino Mar 22 '13 at 08:21
  • war to pom. Curiosity :) I spent a day before realizing gwt compilation was getting skipped. – appbootup Mar 22 '13 at 08:26
  • I can make do with war rather than zip and war ( by extracting the contents when i need into second module from the war itself ). Assume i want to have multi-module project set up of samples where i do not want to compile the sample always instead download the samples compiled js and push it into my Mega Sample aggregator project. – appbootup Mar 22 '13 at 08:28
  • If I understand well, you are saying that you want to publish your example1.war in a maven-repo, then in another module (examples) you want to unpack the static stuff from all exampleX.war and create a new examples.war, right? – Manolo Carrasco Moñino Mar 22 '13 at 12:29
  • @Manolo yes. You can describe it that way. – appbootup Mar 22 '13 at 13:45

2 Answers2

4

To join multiple gwt compiled modules into a single .war file, it is very easy with the maven-dependency-plugin

  1. Package all your gwt examples as habitual (.war), and install them mvn install or mvn deploy if you have a private maven repo.
  2. Create an empty maven module of type war, with no code but with the maven folder structure, you can put any additional stuff you need here like a global src/main/webapp/index.html.
  3. Configure the new module to use the maven-dependency-plugin like shown below, and run 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 and related with the gwt-maven-plugin, like with any other maven pluging, it would be enough to select an appropriate phase of the pom-packaging life cycle (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 disallows compilation when packaging is pom, take a look to line #269 of CompileMojo.java

Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
  • Thank you. This answer's my 3 point. I am still unclear on gwt-maven-plugin behavior of skipping compilation when maven module packaging is "pom". – appbootup Mar 22 '13 at 17:39
  • what is your gwt-maven-plugin configuration?. which phase do you use to execute the gwt:compile goal? – Manolo Carrasco Moñino Mar 22 '13 at 18:56
  • If u note I just change the packaging type in validation sample pom. – appbootup Mar 23 '13 at 06:39
  • sgwt-maven-plugin skip compilation when packaging is pom, so you should select a different packaging or open an issue to the project, updated my answer properly. – Manolo Carrasco Moñino Mar 24 '13 at 07:39
  • That sums it up for all three queries. I will go with the work around for now. Will report on the CompileMojo code later... – appbootup Mar 24 '13 at 16:19
  • We can use Maven [**overlays**](https://maven.apache.org/plugins/maven-war-plugin/overlays.html) feature of war instead of **maven-dependency-plugin**. It will be more easy. – Manu May 16 '13 at 09:56
1

You can create the reusable modules (that you mention as samples in the comments) as separate GWT projects with no EntryPoint. Package them as jar and add the following as resources:

  1. the client side source code
  2. other resource items that will be necessary for the final compilation (images, xml files, etc.)

Something like this:

<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>

That's it, you can reuse it in any other GWT project. When you will do so, you just have to add the dependency (to the reusable module) in the pom.xml and import in the *.gwt.xml.

As for Maven's behaviour, it seems correct. pom packaging is going through package, install and deploy phases and

By default, the compile goal is configured to be executed during the ''prepare-package'' phase to run as late as possible.

You could change the phase in the plugin's execution, but I think it's risky because you can't know when exactly during the package phase will your code get compiled.

Sergio Pelin
  • 874
  • 7
  • 22