Skip to content

Commit b9ba923

Browse files
authored
Merge pull request #7 from vsbogd/gradle-plugin
Support Gradle and Android 7.0
2 parents a6cbff4 + f4a824e commit b9ba923

38 files changed

Lines changed: 1056 additions & 197 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ jobs:
1818
steps:
1919
- checkout
2020

21-
# get dependencies
22-
- run:
23-
name: Get web3j
24-
command: curl -L https://get.web3j.io | bash
2521
# run tests!
2622
- run:
2723
name: Build and run tests
2824
command: |
29-
source $HOME/.web3j/source.sh
3025
mvn install
3126
- run:
3227
name: Upload coverage

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010

1111
## How to build
1212

13-
Install web3j for the first time:
14-
```
15-
curl -L https://get.web3j.io | bash
16-
source $HOME/.web3j/source.sh
17-
```
18-
1913
Build and test:
2014
```
2115
mvn test

gradle-plugin/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# How to use SDK in Android app
2+
3+
## Root project `build.gradle`
4+
5+
Add Maven Central and Jitpack.io repositories into `buildscript/repositories`
6+
section. Maven Central is used to get Gradle Protobuf plugin. Jitpack.io repo
7+
contains SingularityNet SDK dependencies.
8+
```
9+
mavenCentral()
10+
maven {
11+
url 'https://jitpack.io'
12+
}
13+
```
14+
15+
Add SingularityNet and Protobuf plugins into the classpath using
16+
`buildscript/dependencies` section:
17+
```
18+
classpath 'io.singularitynet:snet-sdk-gradle-plugin:1.0-SNAPSHOT'
19+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
20+
```
21+
22+
## Android app `build.gradle` script
23+
24+
Apply SingularityNet SDK and Protobuf plugins.
25+
```
26+
apply plugin: 'io.singularitynet.sdk'
27+
apply plugin: 'com.google.protobuf'
28+
```
29+
30+
Add Jitpack.io repository before `dependencies` section to get SingularityNet
31+
Java SDK dependencies.
32+
```
33+
repositories {
34+
maven {
35+
url 'https://jitpack.io'
36+
}
37+
}
38+
```
39+
40+
Add SingularityNet Java SDK into `dependencies` section:
41+
```
42+
implementation 'io.grpc:grpc-okhttp:1.20.0'
43+
implementation 'org.slf4j:slf4j-android:1.7.30'
44+
implementation 'io.singularitynet:snet-sdk-java:1.0-SNAPSHOT'
45+
```
46+
47+
Add one Gradle task to download and unpack each SingularityNet service API you
48+
are going to use. You should provide at least `orgId`, `serviceId` to specify
49+
service. `javaPackage` to set convenient package for Java files to be
50+
generated. `outputDir` to write resulting protobuf files.
51+
```
52+
tasks.register('getExampleServiceApi', io.singularitynet.sdk.gradle.GetSingularityNetServiceApi) {
53+
orgId = 'snet'
54+
serviceId = 'example-service'
55+
javaPackage = 'io.singularitynet.service.exampleservice'
56+
outputDir = file("$buildDir/proto")
57+
}
58+
```
59+
60+
Add dir which was used to unpack service API protobuf on the previous step into
61+
set of source dirs. Turn on support of Java 8 features.
62+
```
63+
android {
64+
sourceSets {
65+
main {
66+
proto {
67+
srcDir "$buildDir/proto"
68+
}
69+
}
70+
}
71+
compileOptions {
72+
sourceCompatibility = 1.8
73+
targetCompatibility = 1.8
74+
}
75+
}
76+
```
77+
78+
Use Protobuf compiler with gRPC plugin to compile SingularityNet service API
79+
into Java code. gRPC and Protobuf versions below are recommended as they were
80+
used to compile SingularityNet Java SDK.
81+
```
82+
def grpcVersion = '1.20.0'
83+
def protobufVersion = '3.5.1'
84+
def protocVersion = protobufVersion
85+
86+
protobuf {
87+
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
88+
plugins {
89+
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
90+
}
91+
generateProtoTasks {
92+
all()*.builtins { remove java }
93+
all()*.plugins {
94+
grpc {}
95+
java {}
96+
}
97+
}
98+
}
99+
```

gradle-plugin/pom.xml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<parent>
7+
<groupId>io.singularitynet</groupId>
8+
<artifactId>snet-sdk-java-pom</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>snet-sdk-gradle-plugin</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<name>snet-sdk-gradle-plugin</name>
17+
<description>SingularityNet Java SDK Gradle Plugin</description>
18+
<!-- TODO change it to the project's website -->
19+
<url>http://dev.singularitynet.io</url>
20+
21+
<repositories>
22+
<repository>
23+
<id>gradle</id>
24+
<url>https://repo.gradle.org/gradle/libs-releases-local</url>
25+
</repository>
26+
</repositories>
27+
28+
<properties>
29+
<!-- pom's of the higher versions doesn't contain dependencies, so they
30+
require importing more artifacts than simple `gradle-core` -->
31+
<!-- see also Spring Boot example of using Maven to call Gradle
32+
https://github.com/spring-projects/spring-boot/commit/9b15e6b5a3c0fc18372f532063bb43f25abcf984 -->
33+
<gradle.version>3.4</gradle.version>
34+
</properties>
35+
36+
<dependencies>
37+
<!-- compile scope -->
38+
<dependency>
39+
<groupId>io.singularitynet</groupId>
40+
<artifactId>snet-sdk-plugin-core</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.projectlombok</groupId>
44+
<artifactId>lombok</artifactId>
45+
<scope>provided</scope>
46+
</dependency>
47+
<!-- gradle start -->
48+
<dependency>
49+
<groupId>org.codehaus.groovy</groupId>
50+
<artifactId>groovy</artifactId>
51+
<version>2.5.8</version>
52+
<scope>provided</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.gradle</groupId>
56+
<artifactId>gradle-core</artifactId>
57+
<version>${gradle.version}</version>
58+
<scope>provided</scope>
59+
</dependency>
60+
<!-- gradle stop -->
61+
</dependencies>
62+
63+
<build>
64+
65+
<plugins>
66+
67+
<plugin>
68+
<groupId>org.jacoco</groupId>
69+
<artifactId>jacoco-maven-plugin</artifactId>
70+
<executions>
71+
<execution>
72+
<goals>
73+
<goal>prepare-agent</goal>
74+
</goals>
75+
</execution>
76+
<!-- attached to Maven test phase -->
77+
<execution>
78+
<id>report</id>
79+
<phase>test</phase>
80+
<goals>
81+
<goal>report</goal>
82+
</goals>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-javadoc-plugin</artifactId>
90+
</plugin>
91+
92+
</plugins>
93+
94+
</build>
95+
96+
</project>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package io.singularitynet.sdk.gradle;
2+
3+
import org.gradle.api.Task;
4+
import org.gradle.api.DefaultTask;
5+
import org.gradle.api.tasks.Input;
6+
import org.gradle.api.tasks.OutputDirectory;
7+
import org.gradle.api.tasks.TaskAction;
8+
9+
import java.io.File;
10+
import java.net.URL;
11+
import lombok.Setter;
12+
13+
import io.singularitynet.sdk.plugin.ServiceApiGetter;
14+
import io.singularitynet.sdk.plugin.PluginException;
15+
16+
public class GetSingularityNetServiceApi extends DefaultTask implements ServiceApiGetter.Parameters {
17+
18+
@Setter
19+
private String orgId;
20+
@Setter
21+
private String serviceId;
22+
@Setter
23+
private File outputDir;
24+
@Setter
25+
private String javaPackage;
26+
@Setter
27+
private URL ipfsRpcEndpoint;
28+
@Setter
29+
private URL ethereumJsonRpcEndpoint;
30+
@Setter
31+
private String getterEthereumAddress;
32+
@Setter
33+
private String registryAddress;
34+
35+
public GetSingularityNetServiceApi() {
36+
try {
37+
ipfsRpcEndpoint = new URL(ServiceApiGetter.DEFAULT_IPFS_ENDPOINT);
38+
ethereumJsonRpcEndpoint = new URL(ServiceApiGetter.DEFAULT_ETHEREUM_JSON_RPC_ENDPOINT);
39+
getterEthereumAddress = ServiceApiGetter.DEFAULT_GETTER_ETHEREUM_ADDRESS;
40+
registryAddress = ServiceApiGetter.DEFAULT_REGISTRY_ADDRESS;
41+
} catch (java.net.MalformedURLException e) {
42+
throw new IllegalStateException("Unexpected error", e);
43+
}
44+
45+
for (Task task : getProject().getTasksByName("preBuild", false)) {
46+
task.dependsOn(this);
47+
}
48+
}
49+
50+
@Input
51+
public String getOrgId() {
52+
return orgId;
53+
}
54+
55+
@Input
56+
public String getServiceId() {
57+
return serviceId;
58+
}
59+
60+
@OutputDirectory
61+
public File getOutputDir() {
62+
return outputDir;
63+
}
64+
65+
@Input
66+
public String getJavaPackage() {
67+
return javaPackage;
68+
}
69+
70+
@Input
71+
public URL getIpfsRpcEndpoint() {
72+
return ipfsRpcEndpoint;
73+
}
74+
75+
@Input
76+
public URL getEthereumJsonRpcEndpoint() {
77+
return ethereumJsonRpcEndpoint;
78+
}
79+
80+
@Input
81+
public String getGetterEthereumAddress() {
82+
return getterEthereumAddress;
83+
}
84+
85+
@Input
86+
public String getRegistryAddress() {
87+
return registryAddress;
88+
}
89+
90+
@TaskAction
91+
void getSingularityNetServiceApi() {
92+
try {
93+
new ServiceApiGetter(this).run();
94+
} catch (PluginException e) {
95+
throw new RuntimeException("Could not get API", e);
96+
}
97+
}
98+
99+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.singularitynet.sdk.gradle;
2+
3+
import org.gradle.api.Plugin;
4+
import org.gradle.api.Project;
5+
6+
import java.net.URL;
7+
import java.net.MalformedURLException;
8+
9+
public class SnetSdkPlugin implements Plugin<Project> {
10+
11+
@Override
12+
public void apply(Project project) {
13+
}
14+
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
implementation-class=io.singularitynet.sdk.gradle.SnetSdkPlugin

maven-plugin/pom.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<name>snet-sdk-maven-plugin</name>
1515
<description>SingularityNet Java SDK Maven Plugin</description>
1616
<!-- TODO change it to the project's website -->
17-
<url>http://www.example.com</url>
17+
<url>http://dev.singularitynet.io</url>
1818

1919
<properties>
2020
<maven.version>3.3.9</maven.version>
@@ -28,15 +28,12 @@
2828
<!-- compile scope -->
2929
<dependency>
3030
<groupId>io.singularitynet</groupId>
31-
<artifactId>snet-sdk-java</artifactId>
31+
<artifactId>snet-sdk-plugin-core</artifactId>
3232
</dependency>
3333
<dependency>
34-
<groupId>org.slf4j</groupId>
35-
<artifactId>slf4j-api</artifactId>
36-
</dependency>
37-
<dependency>
38-
<groupId>org.apache.commons</groupId>
39-
<artifactId>commons-compress</artifactId>
34+
<groupId>org.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
<scope>provided</scope>
4037
</dependency>
4138
<!-- maven plugin -->
4239
<dependency>

0 commit comments

Comments
 (0)