web3j

Gradle plugin providing tasks to generate web3j contracts from Solidity.

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

org.web3j
ArtifactId

ArtifactId

web3j-gradle-plugin
Last Version

Last Version

4.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

web3j
Gradle plugin providing tasks to generate web3j contracts from Solidity.
Project URL

Project URL

https://web3j.io
Source Code Management

Source Code Management

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

Download web3j-gradle-plugin

How to add to project

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

Dependencies

runtime (3)

Group / Artifact Type Version
gradle.plugin.org.web3j.solidity » solidity-gradle-plugin jar 0.2.3
org.web3j : core jar 4.6.0
org.web3j : codegen jar 4.6.0

Project Modules

There are no modules declared in this project.

Web3j Gradle Plugin

Gradle plugin that generates Web3j Java wrappers from Solidity smart contracts. It smoothly integrates with your project's build lifecycle by adding specific tasks that can be also run independently.

Plugin configuration

To configure the Web3j 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 your project containing Solidity contracts:

./gradlew build

After applying the plugin, the base directory for generated code (by default $buildDir/generated/sources/web3j) will contain a directory for each source set (by default main and test) containing the smart contract wrappers Java classes.

Code generation

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

web3j {
    generatedPackageName = 'com.mycompany.{0}'
    generatedFilesBaseDir = "$buildDir/custom/destination"
    excludedContracts = ['Ownable']
    useNativeJavaTypes = false
}

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

Name Type Default value Description
generatedPackageName String ${group}.web3j or org.web3j.{0} Generated contract wrappers package.
generatedFilesBaseDir String $buildDir/generated/sources/web3j Generated Java code output directory.
excludedContracts String[] [] Excluded contract names from wrapper generation.
includedContracts String[] [] Included contract names from wrapper generation. Has preference over excludedContracts.
useNativeJavaTypes Boolean true Generate smart contract wrappers using native Java types.
addressBitLength int 160 Supported address length in bits, by default Ethereum addresses.

The generatedPackageName is evaluated as a message format string accepting a single parameter between curly brackets ({0}), allowing to format the generated value using the contract name. For convenience, when applied to a Java package name it will be converted to lower case.

For instance, a generatedPackageName set to ${group}.{0} in a project with group com.mycompany, a Solidity contract named MyToken.sol will be generated in the package com.mycompany.mytoken.

Also, the default value contains the ${group} property, which corresponds to your project artifact group (e.g. com.mycompany). If the project does not define a group property, the generated package name will be org.web3j.{0}.

Note that message format parameters are not Gradle properties and should not be preceded by $.

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:

sourceSets {
    main {
        solidity {
            srcDir { 
                "my/custom/path/to/solidity" 
             }
        }
    }
}

Check the Solidity Plugin documentation to configure the smart contracts source code directories.

Output directories for generated smart contract wrappers Java code will be added to your build automatically.

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 the generateContractWrappers task for the project main source set, and a generate[SourceSet]ContractWrappers for each remaining source set (e.g. test).

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
4.6.0
4.5.11
4.5.10
4.5.9
4.5.8
4.5.7
4.5.5
4.5.0
4.4.0
4.3.0
4.1.3
4.0.3
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0