maven 项目执行失败 "maven-thrift-plugin"

maven project failed to execute "maven-thrift-plugin"

我 "brew install thrift" 在 mac(0.11.0) 和 pom.xml:

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.apache.thrift/libthrift -->
    <dependency>
        <groupId>org.apache.thrift</groupId>
        <artifactId>libthrift</artifactId>
        <version>0.11.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
    </dependency>
</dependencies>

<build>
  <plugins>
      <plugin>
          <groupId>org.apache.thrift.tools</groupId>
          <artifactId>maven-thrift-plugin</artifactId>
          <version>0.1.11</version>
          <configuration>
              <thriftExecutable>/usr/local/bin/thrift</thriftExecutable>
              <thriftSourceRoot>src/main/java/thrift</thriftSourceRoot>
              <outputDirectory>src/main/java/gen-java</outputDirectory>
          </configuration>
          <executions>
              <execution>
                  <id>thrift-sources</id>
                  <phase>generate-sources</phase>
                  <goals>
                      <goal>compile</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
  </plugins>
</build>
<repositories>
    <repository>
        <id>Maven Central Repository</id>
        <name>Maven Central Repository</name>
        <url>http://central.maven.org/maven2/</url>
    </repository>
</repositories>

然后mvn包。我想 mvn 应该自动下载我在 pom.xml 中为 "maven-thrift-plugin:jar" 指定的插件,但我得到了:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building java_local 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-thrift-plugin:0.1.11:compile (thrift-sources) @ java_local ---
[ERROR] thrift failed output:

[ERROR] thrift failed error: [FAILURE:generation:1] Error: unknown option java:hashcode

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.405 s
[INFO] Finished at: 2018-09-17T15:48:09+08:00
[INFO] Final Memory: 9M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.thrift.tools:maven-thrift-plugin:0.1.11:compile (thrift-sources) on project java_local: thrift did not exit cleanly. Review output for more information. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

如何解决这个问题?谢谢!

尝试在 settings.xml 中添加 maven 中央存储库:

<repositories>
    <repository>
        <id>Maven Central Repository</id>
        <name>Maven Central Repository</name>
        <url>http://central.maven.org/maven2/</url>
    </repository>
</repositories>

您也可以通过编辑 POM 来执行此项目特定的操作:

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

    <dependencies>
        ...
    </dependencies>

    <repositories>
        <repository>
            <id>Maven Central Repository</id>
            <name>Maven Central Repository</name>
            <url>http://central.maven.org/maven2/</url>
        </repository>
    </repositories>
</project>

<version>0.11.0</version> 是依赖项的有效版本,但不是插件。

将插件版本更改为 <version>0.1.11</version>

然后运行mvn clean install.

那么您的 mvn package 命令应该可以工作了。

来自插件版本 0.1.10 添加配置 <generator>java</generator> 修复问题

      <plugin>
                    <groupId>org.apache.thrift.tools</groupId>
                    <artifactId>maven-thrift-plugin</artifactId>
                    <version>0.1.11</version>
                    <configuration>
    <thriftExecutable>E:\path\to\thrift\thrift-0.12.0.exe</thriftExecutable>
<thriftSourceRoot>${basedir}/src/main/thrift</thriftSourceRoot>
                        <generator>java</generator>
                    </configuration>
                    <executions>
                        <execution>
                            <id>thrift-sources</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>thrift-test-sources</id>
                            <phase>generate-test-sources</phase>
                            <goals>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>