目录
背景
使用命令curl https://flink.apache.org/q/quickstart.sh | bash -s 1.10.0
构建Flink quickstart 时出现了不少坑,作为记录
开始填坑
1. 在语句Generating project in Batch mode卡住
- 日志如下
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
在最后一行语句中卡住了
- 原因分析
curl https://flink.apache.org/q/quickstart.sh | bash -s 1.10.0
其实是先把 脚本quickstart.sh
下载下来,然后再执行该脚本。改脚本的核心部分其实就是以下执行的这个mvn语句
mvn archetype:generate \
-DarchetypeGroupId=org.apache.flink \
-DarchetypeArtifactId=flink-quickstart-java \
-DarchetypeVersion=${1:-1.10.0} \
-DgroupId=org.myorg.quickstart \
-DartifactId=$PACKAGE \
-Dversion=0.1 \
-Dpackage=org.myorg.quickstart \
-DinteractiveMode=false
在最后加上-X
参数(原本的最后一行要补上一个\
),在执行的时候可以打印出详细的日志。改完之后大概是这样:
mvn archetype:generate \
-DarchetypeGroupId=org.apache.flink \
-DarchetypeArtifactId=flink-quickstart-java \
-DarchetypeVersion=${1:-1.10.0} \
-DgroupId=org.myorg.quickstart \
-DartifactId=$PACKAGE \
-Dversion=0.1 \
-Dpackage=org.myorg.quickstart \
-DinteractiveMode=false \
-X
添加完参数后重新运行,可以看到是卡在了下面这个地方
[DEBUG] Searching for remote catalog: http://repo.maven.apache.org/maven2/archetype-catalog.xml
想必就是因为墙的原因吧。
- 解决办法
看到网上一些解法,是直接用浏览器访问上面地址http://repo.maven.apache.org/maven2/archetype-catalog.xml
把文件下载下来,然后再做一些设置,但我试了之后好像有些问题
我采用了另外一个方法,给maven添加国内的镜像源。具体方法为在配置文件settings.xml
(一般在maven安装路径的conf目录下)的标签<mirrors></mirrors>
中间添加以下国内镜像源,最终的效果大概是
<mirrors>
<mirror>
<id>nexus-osc</id>
<mirrorOf>*</mirrorOf>
<name>Nexus osc</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central</url>
</mirror>
</mirrors>
2. Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin 报错
- 日志如下
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[WARNING] Archetype not found in any catalog. Falling back to central repository.
[WARNING] Add a repository with id 'archetype' in your settings.xml if archetype's repository is elsewhere.
[WARNING] The POM for org.apache.flink:flink-quickstart-java:jar:-s is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.172 s
[INFO] Finished at: 2020-05-23T19:49:10+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate (default-cli) on project standalone-pom: The desired archetype does not exist (org.apache.flink:flink-quickstart-java:-s) -> [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
- 原因分析
这个地方 https://github.com/adobe/aem-project-archetype/issues/76#issuecomment-282680691 里面说了这个问题,大概就是新旧版本直接的兼容问题 - 解决办法
把第一个参数archetype:generate
修改为org.apache.maven.plugins:maven-archetype-plugin:2.4:generate
最终的效果大概是下面这样mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \ -DarchetypeGroupId=org.apache.flink \ -DarchetypeArtifactId=flink-quickstart-java \ -DarchetypeVersion=${1:-1.10.0} \ -DgroupId=org.myorg.quickstart \ -DartifactId=$PACKAGE \ -Dversion=0.1 \ -Dpackage=org.myorg.quickstart \ -DinteractiveMode=false