LoginSignup
10
8

More than 5 years have passed since last update.

Java7 環境で maven が失敗する (Received fatal alert: protocol_version)

Posted at

2018/06/18 以降、Java7 環境で mvn clean package とかすると、Maven Central Repository に通信できなくて失敗してます。

Java7 環境

例えばこんな環境です。 (Java7 の Windows Server 2008R2 環境でした。古い...)

> mvn --version

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T03:41:47+09:00)
Maven home: C:\apache-maven-3.6.0\bin\..
Java version: 1.7.0_75, vendor: Oracle Corporation, runtime: C:\Program Files (x86)\xxxxxx\jdk\jre
Default locale: ja_JP, platform encoding: MS932
OS name: "windows server 2008 r2", version: "6.1", arch: "x86", family: "windows"

mvn clean してみる

必要な maven plugin maven-clean-plugin:2.5Maven Central Repository に取りに行ってくれてますが、[ERROR] ... Received fatal alert: protocol_version でエラー死してます。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.805 s
[INFO] Finished at: 2018-12-14T11:46:23+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version -> [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/PluginResolutionException

ここで言ってる Received fatal alert: protocol_version とは、 「あなた TLSv1.0 でアクセスして来たけど、私達 TLSv1.2 しかサポートしてないよ」 という意味です。

Maven Central Repository は TLSv1.2 のみ?

2018/06/18 から、TLSv1.0, TLSv1.1 はサポートなしに変えた様です。

Java7 は TLSv1.0 ?

Java7 では、標準で暗号化プロトコル TLSv1.0, TLSV1.1, TLSv1.2 のサポートがされています。
サポートはされていますが、 Java7 が default で使用するのは TLSv1.0 に設定されています。

なので、JVMの設定やソースコードで明示的に指定しない限り、Java7 では TLSv1.0 を使っちゃいます。

Java アプリが使っている http client library の仕様等にも依るので、一概に Java7 --> default TLSv1.0 とは言えません。注意。

解決策

正攻法はこうです。JVM の起動オプションに -Dhttps.protocols=TLSv1.2 をつけます。

mvn -Dhttps.protocols=TLSv1.2 clean

解決策 (Windows 黒魔術)

Windows の場合は、mvn コマンドはバッチファイルになってますので、直接書き換えて (=黒魔術) 対応できます。

# ↓ のパスは例えば〜です。自分で配置した所に読み替えて下さい。
C:\apache-maven-3.6.0\bin\mvn.cmd

java コマンドを実行している箇所があるので、そこに JVM オプションを追加してやります。

 "%JAVACMD%" ^
   %JVM_CONFIG_MAVEN_PROPS% ^
   %MAVEN_OPTS% ^
   %MAVEN_DEBUG_OPTS% ^
   -classpath %CLASSWORLDS_JAR% ^
   "-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
   "-Dmaven.home=%MAVEN_HOME%" ^
   "-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^
   "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
+  "-Dhttps.protocols=TLSv1.2" ^
   %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%

参考

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8