I have a simple java maven project whose pom.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">






As you can see I am using web3j library to interact with my blockchain and web3j maven plugin to convert my solidity files to java files.

When I run mvn web3j:generate-sources, it successfully runs and converts the solidity files to java files. But when I run the main method of the project from the IDE, it fails with this error: enter image description here

From the error message above, I tried removing the constructor from my solidity file and the pragma line, and then my project builds and runs fine as expected. So, I am thinking my java project is picking the wrong solidity version somehow.

Any tips/hints as to what may be going on here or how to fix this?

1 Answer 1


You can specify solidity version for the web3j-maven-plugin via setting the following property: solidity.version.

In your case, it is already specified as your pom file contains:


So, the plugin will automatically install the right solc version and compile your contracts using it.

Similarily, for the web3j-gradle-plugin

You can specify the version via adding:

solidity {
      version = "0.7.4"

to your build.gradle.

  • 1
    isn't the plugin taking the solidity version from the smart contract itself? If yes, which one holds precedence over the other?
    – Ram Patra
    Apr 1, 2021 at 9:59
  • 2
    Exactly, the plugin takes the version automatically from the smart contracts. However, if you want to force a certain version, you can specify it using that property. So the property takes precedence over the version in the smart contract Apr 2, 2021 at 10:12
  • 1
    Thanks for the clarification. However, this error (shown in the image) was due to Intellij-Solidity plugin and not because of web3j nor solidity. I have removed the plugin from my IDE and it works fine. For some reason, the plugin was validating against an older solidity version.
    – Ram Patra
    Apr 2, 2021 at 11:51
  • 1
    I don't see a link between the two. The plugin is independent unless it is setting some properties somewhere. I am using the Intellij-Solidity plugin also but everything works fine. Apr 2, 2021 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.