Tirias
Tirias

Reputation: 187

Maven GWT compiler compiling twice?

I'm a newbie with maven pom configurations and am stuck with this case. I have googled and also 'stackoverflowed' for an answer, but the solutions I've seen do not work for me.

I have the following project structure in Eclipse Mars:

parent project(folder)
....pom.xml
....ear project(folder)
.......pom.xml
....rest project(war)(folder)
........pom.xml
....front project(war)(folder)
........pom.xml

When I execute maven clean install -e wildfly:deploy I get the client(front) project compiled twice. What am I doing wrong?

Its pom.xml is as follow:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <artifactId>parent</artifactId>
    <groupId>com</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>client</artifactId>
<packaging>war</packaging>
<name>client</name>

<properties>        
    <version.com.google.gwt>2.7.0</version.com.google.gwt>
    <version.org.codehaus.mojo.gwt.maven.plugin>2.7.0</version.org.codehaus.mojo.gwt.maven.plugin>
</properties>

<repositories>
    <repository>
        <id>redhat-techpreview-all-repository</id>
        <url>https://maven.repository.redhat.com/techpreview/all/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>redhat-techpreview-all-repository</id>
        <url>https://maven.repository.redhat.com/techpreview/all/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<dependencyManagement>
    <dependencies>
         <!-- Google Web Toolkit (GWT) -->
         <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>${version.com.google.gwt}</version>
         </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!-- GWT -->
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>${version.com.google.gwt}</version>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-dev</artifactId>
        <version>${version.com.google.gwt}</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.mgwt</groupId>
        <artifactId>mgwt</artifactId>
        <version>2.0.0</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.gwtphonegap</groupId>
        <artifactId>gwtphonegap</artifactId>
        <version>3.5.0.1</version>
    </dependency>

    <dependency>
        <groupId>com.allen-sauer.gwt.log</groupId>
        <artifactId>gwt-log</artifactId>
        <version>3.3.2</version>
    </dependency>
</dependencies>

<build>
    <!-- Maven will append the version to the finalName (which is the name 
        given to the generated war, and hence the context root) -->
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <packagingExcludes>**/client/local/**/*.class</packagingExcludes>
            </configuration>
        </plugin>

        <!-- GWT plugin to compile client-side java code to javascript and 
          to run GWT development mode -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>${version.org.codehaus.mojo.gwt.maven.plugin}</version>
            <configuration>
                <inplace>true</inplace>
                <logLevel>INFO</logLevel>
                <extraJvmArgs>-Xmx512m</extraJvmArgs>
                <!-- Configure GWT's development mode (formerly known as hosted 
                  mode) to not start the default server (embedded jetty), but to download the 
                  HTML host page from the configured runTarget. -->
                <noServer>true</noServer>
                <runTarget>http://localhost:8080/client/index.html</runTarget>
                <!-- <skip>true</skip> -->
            </configuration>
            <executions>
                <execution>
                    <id>gwt-compile</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>gwt-clean</id>
                    <phase>clean</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<profiles>

    <profile>
        <!-- When built in OpenShift the 'openshift' profile will be used when 
            invoking mvn. -->
        <!-- Use this profile for any OpenShift specific customization your app 
            will need. -->
        <!-- By default that is to put the resulting archive into the 'deployments' 
            folder. -->
        <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
        <id>openshift</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${version.war.plugin}</version>
                    <configuration>
                        <outputDirectory>deployments</outputDirectory>
                        <warName>ROOT</warName>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

And the parent's pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<name>parent</name>
<description>Main parent project</description>

<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>client</module>
    <module>projectEar</module>
    <module>server</module>
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- JBoss dependency versions -->
    <version.wildfly.maven.plugin>1.1.0.Alpha5</version.wildfly.maven.plugin>
    <version.jboss.maven.plugin>7.7.Final</version.jboss.maven.plugin>

    <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
    <version.jboss.bom>8.2.2.Final</version.jboss.bom>
    <version.wildfly>9.0.2.Final</version.wildfly>

    <!-- other plugin versions -->
    <version.compiler.plugin>3.1</version.compiler.plugin>
    <version.ear.plugin>2.10.1</version.ear.plugin>
    <version.ejb.plugin>2.5.1</version.ejb.plugin>
    <version.surefire.plugin>2.16</version.surefire.plugin>
    <version.war.plugin>2.6</version.war.plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
</properties>

<dependencyManagement>
    <dependencies>
        <!-- REST Services WAR -->
        <dependency>
            <groupId>com</groupId>
            <artifactId>server</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency> 

        <!-- GWT WAR -->
        <dependency>
            <groupId>com</groupId>
            <artifactId>client</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <pluginManagement>
        <plugins>
            <!-- The WildFly plugin deploys your ear to a local JBoss
                AS container -->
            <!-- Due to Maven's lack of intelligence with EARs we need 
                to configure the wildfly maven plugin to skip deployment for all modules.
                We then enable it specifically in the ear module. -->
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>${version.wildfly.maven.plugin}</version>
                <inherited>true</inherited>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>  

Finally, the EARs pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<name>pEAR</name>
<description>ear module</description>

<modelVersion>4.0.0</modelVersion>

<parent>
    <artifactId>parent</artifactId>
    <groupId>com</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>projectEar</artifactId>
<packaging>ear</packaging>      

<dependencies>
    <dependency>
        <groupId>com</groupId>
        <artifactId>server</artifactId>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>com</groupId>
        <artifactId>client</artifactId>
        <type>war</type>
    </dependency>
</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>${version.ear.plugin}</version>
            <configuration>
                <!-- Tell Maven we are using Java EE 7 -->
                <version>7</version>
                 <!-- Use Java EE ear libraries as needed. Java EE ear libraries 
                    are in easy way to package any libraries needed in the ear, and automatically 
                    have any modules (EJB-JARs and WARs) use them -->
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <fileNameMapping>no-version</fileNameMapping>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <configuration>
                <filename>${project.artifactId}.ear</filename>
                <skip>false</skip>
                <home>C:\Develop\wildfly9</home> 
                <hostname>127.0.0.1</hostname>
                <port>9990</port>
                <username>admin</username>
                <password>password</password>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. -->
        <!-- Use this profile for any OpenShift specific customization your app will need. -->
        <!-- By default that is to put the resulting archive into the 'deployments' folder. -->
        <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
        <id>openshift</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>${version.ear.plugin}</version>
                    <configuration>
                        <outputDirectory>deployments</outputDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>    

If you need more info, please ask. I'm really stuck with this and I'm pretty sure that it is a totally noob failure.

Upvotes: 1

Views: 405

Answers (1)

Tirias
Tirias

Reputation: 187

Finally it was solved by changing the execute maven command, I mean:

I was launching maven throught eclipse like this:

mvn clean install -e wildfly:deploy

And now, after changing this..

mvn clean -e wildfly:deploy

According to documentation, the "deploy" phase in this plugin invokes a "package" phase:

Invokes the execution of the lifecycle phase package prior to executing itself.

Another solution, using the first maven command line is:

mvn clean install -e wildfly:deploy-only

Which avoid the "package" phase. More info aboy

Thanks for the answers!

Upvotes: 1

Related Questions