3

I'm newbie to Hyperledger Fabric. When i instantiate the chaincode written in java after installed on peers from the cli container, there is something wrong:

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

I thought it might be the maven repository's issue, but when i use gradle in my host's terminal, it runs ok like:

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

below is my build.gradle, It is the same as the hyperleger's example chaincode.

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'
    }
}

Is there any way to solve this problem? and what is the difference in running gradle build within host and container?

liuqi
  • 131
  • 1
  • 8

2 Answers2

7

Actually, you should use

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

repo instead of repo from the other answer, since this repo is recommended in official json-schema documentation.

Quote:

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

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

Benas
  • 2,106
  • 2
  • 39
  • 66
  • 1
    Yes, maven { url "https://jitpack.io" }. worked. – user518066 Sep 16 '21 at 11:09
  • I tried both of these urls but didn't work.. not sure why. repositories { maven { url "https://repository.mulesoft.org/nexus/content/repositories/public/" } maven { url 'https://jitpack.io' } } – Raj Dec 04 '21 at 16:02
  • @Raj I think repo URLs have to start with https://, so try to add it to the jitpack.io – Benas Mar 25 '22 at 14:31
  • Thanks for the response @Benas. I figured out the issue. I've an extra character ( .) in the repo URL – Raj Apr 18 '22 at 15:36
6

I searched the maven repository(https://mvnrepository.com/artifact/org.hyperledger.fabric-chaincode-java/fabric-chaincode-shim/1.4.2), found that this dependency is not in maven central repository. After adding repository in build.gradle as follows:

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

it works well now. since i am not familar with gradle, i still wonder why i can build successfully in host while failed in cli container ?

liuqi
  • 131
  • 1
  • 8
  • 1
    'cli' uses 'hyperledger/fabric-javaenv' fabric docker image dynamically to compile the code. You need to enrich this 'hyperledger/fabric-javaenv' with all dependencies for your 'cli' build also to be successful. – Siva Jun 01 '20 at 17:17
  • It would be useful to edit this answer to use the `maven { url 'https://jitpack.io' }` repository instead, as shown in the answer from @Benas, unfortunately the edit queue is full. – James Taylor Sep 27 '21 at 16:24
  • Thanks. For the version I am looking for (1.12.2), this is the repo that has it. I should upgrade and point to whaever the newest one is and point to the most current (1.14 looks like), Not sure where that is. – Hodglem Mar 10 '22 at 20:54