1

我是 Hyperledger Fabric 的新手。当我在 cli 容器的对等点上安装后实例化用 java 编写的链代码时,出现了问题:

FAILURE: Build failed with an exception.

* What went wrong:  
Could not resolve all files for configuration ':compileClasspath'.  
> Could not find com.github.everit-org.json-schema:org.everit.json.schema:1.11.1.
  Searched in the following locations:  
      file:/root/.m2/repository/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.pom
      file:/root/.m2/repository/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.jar
      https://repo.maven.apache.org/maven2/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.pom
      https://repo.maven.apache.org/maven2/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.jar  
  Required by:
      project : > org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.2

我认为这可能是 maven 存储库的问题,但是当我在主机的终端中使用 gradle 时,它​​运行正常,如下所示:

fabric@ubuntu:~/fabric1.4/fabric-samples/chaincode/master-liuqi/java$ sudo /opt/gradle/bin/gradle -b build.gradle build

Task :compileJava
Note: /home/fabric/fabric1.4/fabric-samples/chaincode/master-liuqi/java/src/main/java/org/hyperledger/fabric/example/SimpleChaincode.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

BUILD SUCCESSFUL in 0s  
2 actionable tasks: 2 executed

下面是我的 build.gradle,和 hyperleger 的示例链码一样。

plugins {
    id 'com.github.johnrengelman.shadow' version '2.0.3'
    id 'java'
}

group 'org.hyperledger.fabric-chaincode-java'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

shadowJar {
    baseName = 'chaincode'
    version = null
    classifier = null

    manifest {
        attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
    }
}

有没有办法解决这个问题?在主机和容器中运行 gradle build 有什么区别?

4

2 回答 2

4

我搜索了 maven 存储库(https://mvnrepository.com/artifact/org.hyperledger.fabric-chaincode-java/fabric-chaincode-shim/1.4.2),发现此依赖项不在 maven 中央存储库中。在 build.gradle 中添加存储库后如下:

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url "https://repository.mulesoft.org/nexus/content/repositories/public/"
    }
}

现在效果很好。由于我不熟悉 gradle,我仍然想知道为什么我可以在主机中成功构建而在 cli 容器中失败?

于 2019-07-26T12:31:57.410 回答
3

实际上,您应该使用

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        maven { url 'https://jitpack.io' }
    }
}

repo 而不是来自其他答案的 repo,因为官方json-schema文档中建议使用此 repo。

引用:

将 JitPack 存储库和依赖项添加到您的 pom.xml,如下所示:

(见:https ://github.com/everit-org/json-schema )

于 2021-05-07T11:17:15.910 回答