Ubuntu22.04 解决fabric 安装gradle构建的Java合约超时

问题

fabric安装gradle构建的Java合约时遇到合约代码编译超时问题,如下:

bash 复制代码
$ peer lifecycle chaincode install cp.tar.gz 
Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not build chaincode: docker build failed: docker image build failed: docker build failed: Error returned from build: 1 "+ INPUT_DIR=/chaincode/input
+ OUTPUT_DIR=/chaincode/output
++ mktemp -d
+ TMP_DIR=/tmp/tmp.QxEGc5qu3R
++ find /chaincode/input -name '*.jar'
++ wc -l
+ NUM_JARS=1
+ for DIR in ${INPUT_DIR} ${INPUT_DIR}/src
+ '[' -f /chaincode/input/build.gradle -o -f /chaincode/input/build.gradle.kts ']'
+ '[' -f /chaincode/input/pom.xml ']'
+ for DIR in ${INPUT_DIR} ${INPUT_DIR}/src
+ '[' -f /chaincode/input/src/build.gradle -o -f /chaincode/input/src/build.gradle.kts ']'
+ buildGradle /chaincode/input/src /chaincode/output
+ echo 'Copying from /chaincode/input/src to /tmp/tmp.QxEGc5qu3R'
+ cd /chaincode/input/src
+ tar cf - .
+ cd /tmp/tmp.QxEGc5qu3R
+ tar xf -
Copying from /chaincode/input/src to /tmp/tmp.QxEGc5qu3R
+ cd /tmp/tmp.QxEGc5qu3R
+ echo 'Gradle build'
+ '[' -f ./gradlew ']'
+ chmod +x ./gradlew
Gradle build
+ ./gradlew build shadowJar -x test
Downloading https://services.gradle.org/distributions/gradle-6.5.1-bin.zip

Exception in thread "main" java.net.ConnectException: Connection timed out (Connection timed out)
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
	at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.base/java.net.Socket.connect(Socket.java:609)
	at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:305)
	at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
	at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:509)
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:604)
	at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:910)
	at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:724)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1637)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1542)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
	at org.gradle.wrapper.Download.downloadInternal(Download.java:67)
	at org.gradle.wrapper.Download.download(Download.java:52)
	at org.gradle.wrapper.Install$1.call(Install.java:62)
	at org.gradle.wrapper.Install$1.call(Install.java:48)
	at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
	at org.gradle.wrapper.Install.createDist(Install.java:48)
	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)
"

在logspout中输出为:

由此看到是下载https://services.gradle.org/distributions/gradle-6.5.1-bin.zip文件超时。

解决方案

替换镜像地址

https://services.gradle.org/distributions/gradle-6.5.1-bin.zip替换成https://mirrors.cloud.tencent.com/gradle/gradle-6.5.1-bin.zip。

https://mirrors.cloud.tencent.com/gradle/{版本号}。

修改配置

修改Java工程目录下的gradle/wrapper/gradle-wrapper.properties文件,把distributionUrl=https://services.gradle.org/distributions/gradle-6.5.1-bin.zip 替换成 distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-6.5.1-bin.zip

修maven仓库

在 build.gradle 文件中加入以下代码:

bash 复制代码
repositories {
    maven {
      url 'https://maven.aliyun.com/repository/public/'
    }
    maven {
      url 'https://maven.aliyun.com/repository/central'
    }
  }  

执行命令:

gradle dependencies 或 ./gradlew dependencies 安装依赖

替换后重新操作 链码打包 和安装流程。

相关推荐
Antg2 小时前
[基础] 003 使用github提交作业
web3·智能合约·move·sui
SilentCodeY2 天前
containerd配置私有仓库registry
容器·kubernetes·containerd·镜像·crictl
微刻时光2 天前
Docker镜像分成
java·运维·开发语言·docker·容器·镜像
Blockchina4 天前
Solana链上的Pump狙击机器人与跟单机器人的工作原理及盈利模式
web3·区块链·智能合约·solana·sol机器人
TMDOG6665 天前
微服务架构设计的初次尝试——基于以太坊智能合约 + NestJS 微服务的游戏社区与任务市场系统:架构设计
游戏·微服务·智能合约
电报号dapp1195 天前
ARB链挖矿DApp系统开发模式定制
区块链·智能合约
bjzhang755 天前
Maven vs Gradle,如何选择?
gradle·maven
ItJavawfc6 天前
Grandle 报错_项目无法编译问题解决
android·gradle
孑么7 天前
GDPU Andriod移动应用 Fragment碎片与简易版的新闻应用
android·xml·java·kotlin·gradle·android-studio
大耳猫9 天前
Android gradle和maven国内镜像地址
android·gradle·maven