GWTP Boilerplate Generation with Maven - 构建成功不一致

GWTP Boilerplate Generation with Maven - build success inconsistency

我对 Maven 相当陌生,但我正在使用它,因为这是 GWTP 插件在您创建新项目时提供的功能。我有一些使用 @GenDto 注释创建的 DTO。以下是我的 pom.xml 文件:

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

    <groupId>com.test</groupId>
    <artifactId>MyProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>MyProject</name>

    <properties>
        <!-- client -->
        <gwt.version>2.7.0</gwt.version>
        <gwtp.version>1.5</gwtp.version>
        <gin.version>2.1.2</gin.version>
        <!-- server -->
        <guice.version>3.0</guice.version>
        <resteasy.version>3.0.13.Final</resteasy.version>
        <jbcrypt.version>0.3m</jbcrypt.version>
        <jax-rs.version>1.1.1</jax-rs.version>
        <arcbees.version>1.2</arcbees.version>

        <!-- testing -->
        <junit.version>4.12</junit.version>
        <jukito.version>1.4.1</jukito.version>

        <!-- maven -->
        <gwt-maven-plugin.version>2.7.0</gwt-maven-plugin.version>
        <maven-surefire-plugin.version>2.17</maven-surefire-plugin.version>
        <maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
        <maven-war-plugin.version>2.5</maven-war-plugin.version>
        <maven-resources-plugin.version>2.5</maven-resources-plugin.version>
        <maven-processor-plugin.version>2.0.5</maven-processor-plugin.version>
        <maven-build-helper-plugin.version>1.7</maven-build-helper-plugin.version>

        <target.jdk>1.7</target.jdk>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    </properties>

    <build>
        <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

        <pluginManagement>
            <plugins>

                <plugin>
                    <groupId>org.bsc.maven</groupId>
                    <artifactId>maven-processor-plugin</artifactId>
                    <version>2.2.4</version>
                    <executions>
                        <execution>
                            <id>process</id>
                            <goals>
                                <goal>process</goal>
                            </goals>
                            <phase>generate-sources</phase>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>com.gwtplatform</groupId>
                            <artifactId>gwtp-processors</artifactId>
                            <version>${gwtp.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.5</version>
                    <executions>
                        <execution>
                            <id>add-source</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>${project.build.directory}/generated-sources</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <source>${target.jdk}</source>
                        <target>${target.jdk}</target>
                        <encoding>${project.build.sourceEncoding}</encoding>
                        <compilerArgument>-proc:none</compilerArgument>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${maven-war-plugin.version}</version>
                    <configuration>
                        <archiveClasses>true</archiveClasses>
                    </configuration>
                </plugin>

                <!-- JUnit Testing - skip *.GwtTest cases -->
                <!-- 'mvn test' - runs the Jukito tests -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-surefire-plugin.version}</version>
                    <configuration>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/*GwtTest.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>

                <!-- GWT -->
                <!-- 'mvn gwt:run' - runs development mode -->
                <!-- 'mvn gwt:debug' - runs debug mode -->
                <!-- 'mvn gwt:compile' - compiles gwt -->
                <!-- 'mvn integration-test' - runs the gwt tests (*GwtTest.java) -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>gwt-maven-plugin</artifactId>
                    <version>${gwt-maven-plugin.version}</version>
                    <configuration>
                        <!-- With multiple tests use GwtTestSuite.java for speed -->
                        <includes>**/*GwtTest.java</includes>
                        <bindAddress>0.0.0.0</bindAddress>
                        <extraJvmArgs>-Xss1024K -Xmx1024M -XX:MaxPermSize=256M</extraJvmArgs>
                        <logLevel>TRACE</logLevel>
                        <copyWebapp>true</copyWebapp>
                        <hostedWebapp>${webappDirectory}</hostedWebapp>
                        <runTarget>MyProject.jsp</runTarget>
                        <modules>
                            <module>com.test.MyProject</module>
                        </modules>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

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

        <!-- GWT-Platform -->
        <dependency>
            <groupId>com.gwtplatform</groupId>
            <artifactId>gwtp-mvp-client</artifactId>
            <version>${gwtp.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gwtplatform</groupId>
            <artifactId>gwtp-dispatch-rpc-client</artifactId>
            <version>${gwtp.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gwtplatform</groupId>
            <artifactId>gwtp-dispatch-rpc-server-guice</artifactId>
            <version>${gwtp.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gwtplatform</groupId>
            <artifactId>gwtp-dispatch-rpc-shared</artifactId>
            <version>${gwtp.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gwtplatform</groupId>
            <artifactId>gwtp-dispatch-rest</artifactId>
            <version>${gwtp.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gwtplatform.extensions</groupId>
            <artifactId>dispatch-rest-delegates</artifactId>
            <version>${gwtp.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gwtplatform</groupId>
            <artifactId>gwtp-dispatch-rest-shared</artifactId>
            <version>${gwtp.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gwtplatform</groupId>
            <artifactId>gwtp-processors</artifactId>
            <version>${gwtp.version}</version>
        </dependency>


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.12.1.1</version>
        </dependency>



        <!-- DI -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-servlet</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-assistedinject</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-persist</artifactId>
            <version>${guice.version}</version>
        </dependency>

        <dependency>
            <groupId>com.google.gwt.inject</groupId>
            <artifactId>gin</artifactId>
            <version>${gin.version}</version>
        </dependency>

        <dependency>
            <groupId>org.mindrot</groupId>
            <artifactId>jbcrypt</artifactId>
            <version>${jbcrypt.version}</version>
        </dependency>
        <dependency>
            <groupId>com.arcbees</groupId>
            <artifactId>guicy-resteasy</artifactId>
            <version>${arcbees.version}</version>
        </dependency>

        <!-- REST -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>${resteasy.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
            <version>${resteasy.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-guice</artifactId>
            <version>${resteasy.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>${jax-rs.version}</version>
            <!-- Provided because RestEasy has its own implementation -->
            <scope>provided</scope>
        </dependency>


        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jukito</groupId>
            <artifactId>jukito</artifactId>
            <version>${jukito.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

如果我使用目标 clean gwt:run 进行 Maven 构建,它会工作得很好,但是随后任何仅使用目标 gwt:run 的构建都会出错,显示 duplicate class: com.test.shared.dto.LoginDto.

如果我按照建议 添加 <compilerArgument>-proc:none</compilerArgument>,则后续构建工作。但是,对于最初的 clean gwt:run 目标,它会失败,显示 cannot find symbol: class LoginDto.

有什么方法可以使两个构建保持一致吗?

这是 maven-compiler-plugin 3.2(和 3.1 IIRC)的错误。降级到3.0,在process-classes阶段添加build-helper-maven-compiler将生成的源文件夹添加为源文件夹(重要的是"after compile phase")。