Gradle 在 Hyperledger Fabric 中编译失败 "Could not find com.github.everit-org.json-schema:org.everit.json.schema:1.11.1."

Gradle compile failed "Could not find com.github.everit-org.json-schema:org.everit.json.schema:1.11.1." in Hyperledger Fabric

我是 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 在主机和容器中构建有什么区别?

我搜索了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 容器中失败?

实际上,你应该使用

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

repo 而不是来自其他答案的 repo,因为这个 repo 在官方 json-schema 文档中被推荐。

引用:

Add the JitPack repository and the dependency to your pom.xml as follows:

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