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 安装依赖

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

相关推荐
我是前端小学生4 天前
一文详细梳理Bank合约业务逻辑
智能合约
帅次5 天前
Flutter DropdownButton 详解
android·flutter·ios·kotlin·gradle·webview
竹之却7 天前
【云服务器】在Linux CentOS 7上快速搭建我的世界 Minecraft Fabric 服务器搭建,Fabric 模组详细搭建教程
linux·运维·服务器·centos·fabric·我的世界服务器搭建·我的世界模组
Blockchina7 天前
第 4 章 | Solidity安全 权限控制漏洞全解析
安全·web3·区块链·智能合约·solidity
Blockchina7 天前
第十四章 | DeFi / DAO / GameFi 项目高级实战
web3·区块链·智能合约·solidity
龙兵兵科技7 天前
利用智能合约技术打破线下陪玩私单僵局的可行性分析
智能合约·软件开发·线下陪玩·同城陪玩
渗透测试老鸟-九青8 天前
记一次常规的网络安全渗透测试
运维·服务器·安全·web安全·区块链·智能合约
牛andmore牛8 天前
3、fabric实现多机多卡训练
深度学习·神经网络·fabric·fabric多机多卡
microhex8 天前
一文了解Gradle 依赖管理(五)- 依赖管理&缓存依赖
缓存·gradle·maven
我是前端小学生9 天前
手摸手带你用anchor框架写一个Bank链上程序
智能合约