Skip to content

Commit 36d6f6c

Browse files
authored
Remove web3j dependency (#17)
* Make code backwards compatible with previous Gradle versions * Remove web3j dependency and update README * Update Solidity plugin version
1 parent 8283a5e commit 36d6f6c

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
web3j Gradle Plugin
22
===================
33

4-
Gradle plugin that generates [web3j](https://web3j.io/) Java wrappers from Solidity smart contracts.
4+
Gradle plugin that generates [web3j][web3j] Java wrappers from Solidity smart contracts.
55
It smoothly integrates with your project's build lifecycle by adding specific tasks that can be also
66
run independently.
77

@@ -11,6 +11,8 @@ Before you start, you will need to install the
1111
[Solidity compiler](https://solidity.readthedocs.io/en/latest/installing-solidity.html)
1212
if is not already installed in your computer.
1313

14+
In addition, the minimum Gradle version to run the plugin is `4.9` and the recommended `5.2.x`.
15+
1416
### Using the `buildscript` convention
1517

1618
To install the web3j Plugin using the old Gradle `buildscript` convention, you should add
@@ -23,7 +25,7 @@ buildscript {
2325
mavenCentral()
2426
}
2527
dependencies {
26-
classpath 'org.web3j:web3j-gradle-plugin:4.1.1'
28+
classpath 'org.web3j:web3j-gradle-plugin:4.1.2'
2729
}
2830
}
2931
@@ -37,7 +39,7 @@ build file:
3739

3840
```groovy
3941
plugins {
40-
id 'org.web3j' version '4.1.1'
42+
id 'org.web3j' version '4.1.2'
4143
}
4244
```
4345

@@ -51,6 +53,18 @@ After applying the plugin, the base directory for generated code (by default
5153
`$buildDir/generated/source/web3j`) will contain a directory for each source set
5254
(by default `main` and `test`) containing the smart contract wrappers Java classes.
5355

56+
### Project dependencies
57+
58+
The plugin requires the core [web3j][web3j] dependency to be declared in your project.
59+
The minimum version is 4.0 but is recommended to use the
60+
[latest available release](https://github.com/web3j/web3j/releases).
61+
62+
```groovy
63+
dependencies {
64+
implementation "org.web3j:core:$web3jVersion"
65+
}
66+
```
67+
5468
## Code generation
5569

5670
The `web3j` DSL allows to configure the generated code, e.g.:
@@ -125,3 +139,5 @@ To obtain a list and description of all added tasks, run the command:
125139
```
126140
./gradlew tasks --all
127141
```
142+
143+
[web3j]: https://web3j.io/

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jacocoTestReport {
2828
}
2929

3030
ext {
31-
web3jVersion = version
32-
solidityPluginVersion = '0.1.3'
31+
web3jVersion = '4.1.1'
32+
solidityPluginVersion = '0.1.4'
3333
junitVersion = '4.12'
3434

3535
ossrhUsername = project.hasProperty('ossrhUsername') ? project.property('ossrhUsername') : System.getenv('OSSRH_USERNAME')

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group=org.web3j
2-
version=4.1.1
2+
version=4.1.2

src/main/java/org/web3j/gradle/plugin/Web3jPlugin.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import org.gradle.api.Plugin;
88
import org.gradle.api.Project;
99
import org.gradle.api.file.SourceDirectorySet;
10+
import org.gradle.api.internal.file.DefaultSourceDirectorySet;
11+
import org.gradle.api.internal.file.IdentityFileResolver;
12+
import org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory;
1013
import org.gradle.api.plugins.Convention;
1114
import org.gradle.api.plugins.JavaPlugin;
1215
import org.gradle.api.plugins.JavaPluginConvention;
@@ -24,13 +27,12 @@
2427
*/
2528
public class Web3jPlugin implements Plugin<Project> {
2629

27-
public static final String ID = "org.web3j";
30+
static final String ID = "org.web3j";
2831

2932
public void apply(final Project target) {
3033
target.getPluginManager().apply(JavaPlugin.class);
3134
target.getPluginManager().apply(SolidityPlugin.class);
3235
target.getExtensions().create(Web3jExtension.NAME, Web3jExtension.class, target);
33-
target.getDependencies().add("implementation", "org.web3j:core:4.1.1");
3436

3537
final SourceSetContainer sourceSets = target.getConvention()
3638
.getPlugin(JavaPluginConvention.class).getSourceSets();
@@ -65,7 +67,7 @@ private void configure(final Project project, final SourceSet sourceSet) {
6567
generateTaskName, GenerateContractWrappers.class);
6668

6769
// Set the sources for the generation task
68-
task.setSource(buildSourceDirectorySet(project, sourceSet));
70+
task.setSource(buildSourceDirectorySet(sourceSet));
6971
task.setDescription("Generates web3j contract wrappers for "
7072
+ sourceSet.getName() + " source set.");
7173

@@ -89,13 +91,14 @@ private void configure(final Project project, final SourceSet sourceSet) {
8991
compileJava.dependsOn(task);
9092
}
9193

92-
private SourceDirectorySet buildSourceDirectorySet(
93-
final Project project, final SourceSet sourceSet) {
94+
private SourceDirectorySet buildSourceDirectorySet(final SourceSet sourceSet) {
9495

9596
final String displayName = capitalize((CharSequence) sourceSet.getName()) + " Solidity ABI";
9697

97-
final SourceDirectorySet directorySet = project.getObjects()
98-
.sourceDirectorySet(sourceSet.getName(), displayName);
98+
final SourceDirectorySet directorySet = new DefaultSourceDirectorySet(
99+
sourceSet.getName(), displayName,
100+
new IdentityFileResolver(),
101+
new DefaultDirectoryFileTreeFactory());
99102

100103
directorySet.srcDir(buildOutputDir(sourceSet));
101104
directorySet.include("**/*.abi");

src/test/java/org/web3j/gradle/plugin/Web3jPluginTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
1616
import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertNotNull;
20-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.Assert.*;
2118

2219
public class Web3jPluginTest {
2320

@@ -57,6 +54,9 @@ public void generateContractWrappers() throws IOException {
5754
"}\n" +
5855
"repositories {\n" +
5956
" mavenCentral()\n" +
57+
"}\n" +
58+
"dependencies {\n" +
59+
" implementation \"org.web3j:core:4.1.1\"\n" +
6060
"}\n";
6161

6262
Files.write(buildFile.toPath(), buildFileContent.getBytes());

0 commit comments

Comments
 (0)