我已经在Mac(0.11.0)和pom.xml中“简单安装了Thrift”:
<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
如何解决此问题?谢谢!
答案 0 :(得分:2)
<version>0.11.0</version>
是依赖项的有效版本,而不是插件。
将插件版本更改为<version>0.1.11</version>
。
然后运行mvn clean install
。
然后您的mvn package
命令应该起作用。
答案 1 :(得分:1)
尝试在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>
答案 2 :(得分:0)
来自插件版本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>