【问题标题】:Why is Gin generating source files in the "target/classes" directory?为什么 Gin 在“target/classes”目录中生成源文件?
【发布时间】:2014-02-15 01:45:47
【问题描述】:

我正在使用 Maven 构建我的 GWT 项目。我正在使用Gin 生成一些样板代码:

package com.lokur.motd.client.events;

import com.gwtplatform.dispatch.annotation.GenEvent;

@GenEvent
public class EditorChange {
}

但是,当我运行“mvn clean install”命令时,Maven 正在target/classes/com/lokur/motd/client/events 目录中生成与 Gin 相关的 Java 源代码。为什么有.java 文件进入classes 目录?

我正在使用下面的Maven插件在target/generated-sources文件夹中生成Java源代码:

<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>2.0.5</version>
    <executions>
        <execution>
            <id>process</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>target/generated-sources/apt</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

在这种情况下,将生成两个EditorChangeEvent.java 文件:一个在generated-sources 文件夹中; target/classes/&lt;..package..&gt; 文件夹中的另一个。 因此,导致以下编译失败:

duplicate class:
com.lokur.motd.client.events.EditorChangeEvent

【问题讨论】:

    标签: java maven gwt maven-2 gwt-gin


    【解决方案1】:

    虽然无法弄清楚为什么“Java 源文件”会进入“类”目录,但问题在于我们项目支持的 GWT 版本。 它不支持@GenEvent,因为该项目未配置为使用 Gin。因此,手动创建 Event 和 Handler 类,而不是依赖 Gin 的注解。现在,它运作良好。关闭此线程。

    【讨论】:

      【解决方案2】:

      问题是 org.bsc.maven.maven-processor-plugin 和编译器插件正在为不同的文件夹生成(相同的)源。解决方案是禁用一个处理器。在我的解决方案中,我禁用了 org.bsc.maven.maven-processor-plugin link

      【讨论】:

        猜你喜欢
        • 2012-09-08
        • 1970-01-01
        • 1970-01-01
        • 2021-07-31
        • 2016-01-19
        • 1970-01-01
        • 1970-01-01
        • 2015-03-17
        • 1970-01-01
        相关资源
        最近更新 更多