web3j-gradle-plugin icon indicating copy to clipboard operation
web3j-gradle-plugin copied to clipboard

Unable to compile solidity with gradle plugin

Open bhardwahnitish19 opened this issue 3 years ago • 0 comments

I have a java project and a simple-storage smart contract which I am trying to compile and generate java based code using web3j gradle plugin. It's able to generate the code but throws a compilation error:

incompatible types: inference variable T has incompatible bounds equality constraints: List upper bounds: Type where T is a type-variable: T extends Type declared in method executeRemoteCallSingleValueReturn(Function)

Gradle version is: gradle-6.3

Generate code at which we got error:

 error: incompatible types: inference variable T has incompatible bounds
        return executeRemoteCallSingleValueReturn(function);
                                                 ^
    equality constraints: List
    upper bounds: Type
  where T is a type-variable:
    T extends Type declared in method <T>executeRemoteCallSingleValueReturn(Function)

Solidity Contract:

pragma solidity ^0.4.22 <0.9.0;
pragma experimental ABIEncoderV2;

contract Project
{
  struct ProjectDetails {
     bytes32 id;
     bytes32 projectId;
  }

  bytes32[] public projectDetailsIdArray;
  mapping(bytes32 => ProjectDetails)public ProjectDetailsMapping;

  function ReadAllProjects() public view returns (ProjectDetails[] memory){
          ProjectDetails[] memory ret = new ProjectDetails[](projectDetailsIdArray.length);
          for (uint i=0; i<projectDetailsIdArray.length; i++){
          bytes32 _id=projectDetailsIdArray[i];
          ProjectDetails storage temp = ProjectDetailsMapping[_id];
          ret[i] = temp;
          }
          return ret;
    }

}

Gradle build: Gradle version is: gradle-6.3

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.6.1/userguide/java_library_plugin.html
 */

plugins {
   id 'org.springframework.boot' version '2.4.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'war'
    id "org.web3j" version "4.9.4"
}

group = 'com.gateway'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}

dependencies {
    implementation 'org.web3j:core:4.9.0'
implementation group: 'org.web3j', name: 'crypto', version: '4.9.0'
    testImplementation 'junit:junit:4.12'
    implementation 'org.junit.jupiter:junit-jupiter:5.6.2'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
    testImplementation 'org.assertj:assertj-core:3.11.1'
    testImplementation 'org.mockito:mockito-core:2.+'

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'junit', module: 'junit'
    }


}
test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }
}

web3j {
    generatedPackageName = 'com.gateway.generated'
    generatedFilesBaseDir = "$projectDir/src"
    //excludedContracts = ['Ownable']
    useNativeJavaTypes = false
}

bhardwahnitish19 avatar Sep 20 '22 03:09 bhardwahnitish19