Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Basic examples to use Gradle 7.4.2. #79

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Basic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'base'
}

wrapper {
gradleVersion = '7.4.2'
distributionType = Wrapper.DistributionType.BIN
}
12 changes: 0 additions & 12 deletions Basic/constants.properties

This file was deleted.

127 changes: 51 additions & 76 deletions Basic/cordapp-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,104 +1,80 @@
buildscript {//properties that you need to build the project
Properties constants = new Properties()
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
import static org.gradle.jvm.toolchain.JavaLanguageVersion.of
import net.corda.plugins.Cordform

ext {
corda_release_group = constants.getProperty("cordaReleaseGroup")
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
corda_release_version = constants.getProperty("cordaVersion")
corda_core_release_version = constants.getProperty("cordaCoreVersion")
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
kotlin_version = constants.getProperty("kotlinVersion")
junit_version = constants.getProperty("junitVersion")
quasar_version = constants.getProperty("quasarVersion")
log4j_version = constants.getProperty("log4jVersion")
slf4j_version = constants.getProperty("slf4jVersion")
corda_platform_version = constants.getProperty("platformVersion").toInteger()
//springboot
spring_boot_version = '2.0.2.RELEASE'
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
}

repositories {
mavenLocal()
mavenCentral()

maven { url 'https://software.r3.com/artifactory/corda-releases' }
}
plugins {
id 'net.corda.plugins.cordformation'
id 'base'
}

dependencies {
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
configurations {
ganache {
canBeConsumed = false
transitive = false
}
}

allprojects {//Properties that you need to compile your project (The application)
apply from: "${rootProject.projectDir}/repositories.gradle"
apply plugin: 'java'

repositories {
mavenLocal()
subprojects { //Properties that you need to compile your project (The application)
pluginManager.withPlugin('java') {
java {
toolchain {
languageVersion = of(8)
}
}

mavenCentral()
maven { url 'https://software.r3.com/artifactory/corda' }
maven { url 'https://jitpack.io' }
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
}
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
def subPath = it.path
pluginManager.withPlugin('net.corda.plugins.cordapp') {
rootProject.dependencies {
ganache project(path: subPath, configuration: 'cordaCordapp')
}
}

jar {
// This makes the JAR's SHA-256 hash repeatable.
preserveFileTimestamps = false
reproducibleFileOrder = true
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}

apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'net.corda.plugins.quasar-utils'

sourceSets {
main {
resources {
srcDir rootProject.file("config/dev")
configurations.matching { it.name.endsWith("Classpath") }.configureEach {
resolutionStrategy {
dependencySubstitution {
substitute module('com.fasterxml.jackson.module:jackson-module-kotlin') with module("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.7")
substitute module('org.gradle:gradle-tooling-api') with module("org.gradle:gradle-tooling-api:${gradle.gradleVersion}")
}
}
}
}

//Module dependencis
dependencies {
// Corda dependencies.
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
cordaRuntime "$corda_release_group:corda:$corda_release_version"
cordaBootstrapper "$corda_release_group:corda-node-api:$corda_release_version"
cordaBootstrapper "org.slf4j:slf4j-simple:$slf4j_version"
corda "$corda_release_group:corda:$corda_release_version"

// CorDapp dependencies.
cordapp project(":workflows")
cordapp project(":contracts")

cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
cordapp project(':workflows')
cordapp project(':contracts')
}

//Task to deploy the nodes in order to bootstrap a network
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
//Task to build the jar for ganache.
tasks.register('ganache') {
dependsOn configurations.ganache.buildDependencies
doLast {
copy {
from configurations.ganache
into layout.buildDirectory.dir('libs')
}
}
}

tasks.register('deployNodes', Cordform) {
/* This property will load the CorDapps to each of the node by default, including the Notary. You can find them
* in the cordapps folder of the node at build/nodes/Notary/cordapps. However, the notary doesn't really understand
* the notion of cordapps. In production, Notary does not need cordapps as well. This is just a short cut to load
* the Corda network bootstrapper.
*/
nodeDefaults {
projectCordapp {
deploy = false
}
cordapp project(':contracts')
cordapp project(':workflows')
cordapp project(':contracts')
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
runSchemaMigration = true //This configuration is for any CorDapps with custom schema, We will leave this as true to avoid
//problems for developers who are not familiar with Corda. If you are not using custom schemas, you can change
//it to false for quicker project compiling time.
Expand All @@ -111,6 +87,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
address("localhost:10003")
adminAddress("localhost:10043")
}
rpcUsers = []
}
node {
name "O=PartyA,L=London,C=GB"
Expand All @@ -119,7 +96,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
address("localhost:10006")
adminAddress("localhost:10046")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
}
node {
name "O=PartyB,L=New York,C=US"
Expand All @@ -128,6 +104,5 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
address("localhost:10009")
adminAddress("localhost:10049")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
}
}
40 changes: 23 additions & 17 deletions Basic/cordapp-example/clients/build.gradle
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
apply plugin: 'org.springframework.boot'
plugins {
id 'org.springframework.boot'
id 'java'
}

sourceSets {
main {
resources {
srcDir rootProject.file("config/dev")
srcDir file("$rootDir/config/dev")
}
}
}

dependencies {
// Corda dependencies.
compile "$corda_release_group:corda-rpc:$corda_release_version"
compile "net.corda:corda-jackson:$corda_release_version"
implementation "$corda_release_group:corda-rpc:$corda_release_version"
implementation "net.corda:corda-jackson:$corda_release_version"

// CorDapp dependencies.
compile project(":contracts")
compile project(":workflows")
compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") {
implementation project(':contracts')
implementation project(':workflows')
implementation("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
}
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
compile "org.apache.logging.log4j:log4j-web:${log4j_version}"
compile "org.slf4j:jul-to-slf4j:$slf4j_version"
runtimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
runtimeOnly "org.apache.logging.log4j:log4j-web:$log4j_version"
}


springBoot {
mainClassName = "net.corda.samples.example.webserver.Starter"
mainClassName = "net.corda.samples.example.webserver.ServerKt"
}

/* The Client is the communication channel between the external and the node. This task will help you immediately
* execute your rpc methods in the main method of the client.kt. You can somewhat see this as a quick test of making
* RPC calls to your nodes.
*/
task runTestClient(type: JavaExec, dependsOn: assemble) {
tasks.register('runTestClient', JavaExec) {
dependsOn assemble
classpath = sourceSets.main.runtimeClasspath
main = 'net.corda.samples.example.webserver.Client'
main = 'net.corda.samples.example.ClientKt'
args 'localhost:10006', 'user1', 'test'
}

/* This task will start the springboot server that connects to your node (via RPC connection). All of the http requests
* are in the Controller file. You can leave the Server.kt and NodeRPCConnection.kt file untouched for your use.
*/
task runPartyAServer(type: JavaExec, dependsOn: assemble) {
tasks.register('runPartyAServer', JavaExec) {
dependsOn assemble
classpath = sourceSets.main.runtimeClasspath
main = 'net.corda.samples.example.webserver.Starter'
main = 'net.corda.samples.example.webserver.ServerKt'
args '--server.port=50005', '--config.rpc.host=localhost', '--config.rpc.port=10006', '--config.rpc.username=user1', '--config.rpc.password=test'
}

task runPartyBServer(type: JavaExec, dependsOn: assemble) {
tasks.register('runPartyBServer', JavaExec) {
dependsOn assemble
classpath = sourceSets.main.runtimeClasspath
main = 'net.corda.samples.example.webserver.Starter'
main = 'net.corda.samples.example.webserver.ServerKt'
args '--server.port=50006', '--config.rpc.host=localhost', '--config.rpc.port=10009', '--config.rpc.username=user1', '--config.rpc.password=test'
}
34 changes: 10 additions & 24 deletions Basic/cordapp-example/contracts/build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
plugins {
id 'net.corda.plugins.cordapp'
}

cordapp {
targetPlatformVersion corda_platform_version
minimumPlatformVersion corda_platform_version
targetPlatformVersion corda_platform_version.toInteger()
minimumPlatformVersion corda_platform_version.toInteger()
contract {
name "Cordapp-example Contracts"
name "Example-Cordapp Contracts"
vendor "Corda Open Source"
licence "Apache License, Version 2.0"
versionId 1
}
}

sourceSets {
main{
java {
srcDir 'src/main/java'
java.outputDir = file('bin/main')
}
}
test{
java{
srcDir 'src/test/java'
java.outputDir = file('bin/test')
}
}
}

dependencies {
testImplementation "$corda_release_group:corda-node-driver:$corda_release_version"

// Corda dependencies.
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
cordaRuntime "$corda_release_group:corda:$corda_release_version"
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
}
cordaProvided "$corda_core_group:corda-core:$corda_release_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import net.corda.testing.node.MockServices;
import org.junit.Test;

import static java.util.Arrays.asList;
import static net.corda.testing.node.NodeTestUtils.ledger;

public class ContractTests {
static private final MockServices ledgerServices = new MockServices();
static private final TestIdentity megaCorp = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
static private final TestIdentity miniCorp = new TestIdentity(new CordaX500Name("MiniCorp", "London", "GB"));
static private final int iouValue = 1;
private static final TestIdentity megaCorp = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
private static final TestIdentity miniCorp = new TestIdentity(new CordaX500Name("MiniCorp", "London", "GB"));
private static final int iouValue = 1;

private final MockServices ledgerServices = new MockServices();

@Test
public void transactionMustIncludeCreateCommand() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package net.corda.samples.example.contracts;

import net.corda.samples.example.states.IOUState;
import net.corda.testing.node.MockServices;
import org.junit.Test;

public class StateTests {
private final MockServices ledgerServices = new MockServices();
import static org.junit.Assert.assertSame;

public class StateTests {
@Test
public void hasAmountFieldOfCorrectType() throws NoSuchFieldException {
// Does the message field exist?
IOUState.class.getDeclaredField("value");
// Is the message field of the correct type?
assert(IOUState.class.getDeclaredField("value").getType().equals(Integer.class));
assertSame(IOUState.class.getDeclaredField("value").getType(), Integer.class);
}
}
}
22 changes: 21 additions & 1 deletion Basic/cordapp-example/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
org.gradle.jvmargs=-XX:+UseG1GC -Xmx1g -Dfile.encoding=UTF-8
org.gradle.java.installations.auto-download=false
org.gradle.caching=false

name=Example Cordapp
group=com.example
version=0.1
version=1.0

# Artifactory
artifactoryContextUrl = https://software.r3.com/artifactory

corda_release_group=net.corda
corda_core_group=net.corda
corda_release_version=4.9
corda_platform_version=10
corda_gradle_plugins_version=5.1.0-RC01
junit_version=4.13.2
quasar_version=0.7.14_r3
log4j_version=2.17.1
slf4j_version=1.7.30
netty_version=4.1.22.Final

spring_boot_version=2.3.12.RELEASE
Binary file not shown.
Loading