Solidity Gradle Plugin

Gradle plugin providing tasks to compile Solidity contracts.

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

org.web3j
ArtifactId

ArtifactId

solidity-gradle-plugin
Last Version

Last Version

0.1.6
Release Date

Release Date

Type

Type

jar
Description

Description

Solidity Gradle Plugin
Gradle plugin providing tasks to compile Solidity contracts.
Project URL

Project URL

https://github.com/web3j/solidity-gradle-plugin
Source Code Management

Source Code Management

https://github.com/web3j/solidity-gradle-plugin

Download solidity-gradle-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/org.web3j/solidity-gradle-plugin/ -->
<dependency>
    <groupId>org.web3j</groupId>
    <artifactId>solidity-gradle-plugin</artifactId>
    <version>0.1.6</version>
</dependency>
// https://jarcasting.com/artifacts/org.web3j/solidity-gradle-plugin/
implementation 'org.web3j:solidity-gradle-plugin:0.1.6'
// https://jarcasting.com/artifacts/org.web3j/solidity-gradle-plugin/
implementation ("org.web3j:solidity-gradle-plugin:0.1.6")
'org.web3j:solidity-gradle-plugin:jar:0.1.6'
<dependency org="org.web3j" name="solidity-gradle-plugin" rev="0.1.6">
  <artifact name="solidity-gradle-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.web3j', module='solidity-gradle-plugin', version='0.1.6')
)
libraryDependencies += "org.web3j" % "solidity-gradle-plugin" % "0.1.6"
[org.web3j/solidity-gradle-plugin "0.1.6"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Solidity Gradle Plugin

Simple Gradle plugin used by the Web3j plugin to compile Solidity contracts, but it can be used in any standalone project for this purpose.

Plugin configuration

To configure the Solidity Gradle Plugin using the plugins DSL or the legacy plugin application, check the plugin page. The minimum Gradle version to run the plugin is 5.+.

Then run this command from your project containing Solidity contracts:

./gradlew build

After the task execution, the base directory for compiled code (by default $buildDir/resources/solidity) will contain a directory for each source set (by default main and test), and each of those a directory with the compiled code.

Code generation

The solidity DSL allows to configure the generated code, e.g.:

solidity {
    outputComponents = [BIN, ABI, ASM_JSON]
    optimizeRuns = 500
}

The properties accepted by the DSL are listed in the following table:

Name Type Default value Description
executable String null (bundled with the plugin) Solidity compiler path.
version String null (defined by contract's pragma) Solidity compiler version.
overwrite Boolean true Overwrite existing files.
resolvePackages Boolean true Resolve third-party contract packages.
optimize Boolean true Enable byte code optimizer.
optimizeRuns Integer 200 Set for how many contract runs to optimize.
prettyJson Boolean false Output JSON in pretty format. Enables the combined JSON output.
ignoreMissing Boolean false Ignore missing files.
allowPaths List<String> ['src/main/solidity', 'src/test/solidity', ...] Allow a given path for imports.
pathRemappings Map<String, String> [ : ] Remaps contract imports to target path.
evmVersion EVMVersion BYZANTIUM Select desired EVM version.
outputComponents OutputComponent[] [BIN, ABI] List of output components to produce.
combinedOutputComponents CombinedOutputComponent[] [BIN, BIN_RUNTIME, SRCMAP, SRCMAP_RUNTIME] List of output components in combined JSON output.

Notes:

  • Setting the executable property will disable the bundled solc and use your local or containerized executable:
solidity {
    executable = "docker run --rm -v $projectDir/src:/src -v $projectDir/build:/build ethereum/solc:0.6.4-alpine"
    version = '0.4.15'
}
  • Use version to change the bundled Solidity version. Check the Solidity releases for all available versions.
  • allowPaths contains all project's Solidity source sets by default.

Source sets

By default, all .sol files in $projectDir/src/main/solidity will be processed by the plugin. To specify and add different source sets, use the sourceSets DSL. You can also set your preferred output directory for compiled code.

sourceSets {
    main {
        solidity {
            srcDir {
                "my/custom/path/to/solidity"
             }
             output.resourcesDir = file('out/bin/compiledSol') 
        }
    }
}

Gradle Node Plugin

The plugin makes use of the Node plugin to resolve third-party contract dependencies. It currently supports:

When importing libraries from @openzeppeling/contracts in your Solidity contract the plugin will use the task resolveSolidity to generate a package.json file in order to be used by the Node plugin. By default, package.json will be generated under the build/ directory. If you with do define your own package.json you need to add the following snippet in your build.gradle file.

node {
    nodeProjectDir = file("my/custom/node/directory")
}

The plugin will look for the package.json file in the directory set and will also download the node modules under the same directory.

Plugin tasks

The Java Plugin adds tasks to your project build using a naming convention on a per source set basis (i.e. compileJava, compileTestJava).

Similarly, the Solidity plugin will add a:

  • resolveSolidity task for all project Solidity sources.
  • compileSolidity task for the project main source set.
  • compile<SourceSet>Solidity for each remaining source set. (e.g. compileTestSolidity for the test source set, etc.).

To obtain a list and description of all added tasks, run the command:

./gradlew tasks --all
org.web3j

web3j

JVM language projects for working with Blockchains

Versions

Version
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0