Skip to content

Commit

Permalink
CORDA-686 - Split Cordapp gradle plugin from cordformation (corda#1817)
Browse files Browse the repository at this point in the history
Added CorDapp gradle plugin written in Kotlin and bumped the version of gradle plugins to 2.0.0 to reflect that this backwards incompatible change is a part of the on going stabilisation of the Corda gradle plugin suite.
  • Loading branch information
Clintonio authored Oct 9, 2017
1 parent 747830f commit 484cf75
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ buildscript {
classpath "net.corda.plugins:publish-utils:$gradle_plugins_version"
classpath "net.corda.plugins:quasar-utils:$gradle_plugins_version"
classpath "net.corda.plugins:cordformation:$gradle_plugins_version"
classpath "net.corda.plugins:cordapp:$gradle_plugins_version"
classpath "net.corda.plugins:api-scanner:$gradle_plugins_version"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
Expand Down Expand Up @@ -180,21 +181,21 @@ repositories {

// Required for building out the fat JAR.
dependencies {
cordaCompile project(':node')
compile project(':node')
compile "com.google.guava:guava:$guava_version"

// Set to corda compile to ensure it exists now deploy nodes no longer relies on build
cordaCompile project(path: ":node:capsule", configuration: 'runtimeArtifacts')
cordaCompile project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
compile project(path: ":node:capsule", configuration: 'runtimeArtifacts')
compile project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')

// For the buildCordappDependenciesJar task
cordaRuntime project(':client:jfx')
cordaRuntime project(':client:mock')
cordaRuntime project(':client:rpc')
cordaRuntime project(':core')
cordaRuntime project(':confidential-identities')
cordaRuntime project(':finance')
cordaRuntime project(':webserver')
runtime project(':client:jfx')
runtime project(':client:mock')
runtime project(':client:rpc')
runtime project(':core')
runtime project(':confidential-identities')
runtime project(':finance')
runtime project(':webserver')
testCompile project(':test-utils')
}

Expand Down
5 changes: 1 addition & 4 deletions confidential-identities/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ apply plugin: 'kotlin'
apply plugin: CanonicalizerPlugin
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'com.jfrog.artifactory'

description 'Corda Experimental Confidential Identities'

dependencies {
// Note the :confidential-identities module is a CorDapp in its own right
// and CorDapps using :confidential-identities features should use 'cordapp' not 'compile' linkage.
cordaCompile project(':core')
compile project(':core')

// Quasar, for suspendable fibres.
compileOnly "co.paralleluniverse:quasar-core:$quasar_version:jdk8"
Expand Down
2 changes: 1 addition & 1 deletion constants.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gradlePluginsVersion=1.1.2
gradlePluginsVersion=2.0.0
kotlinVersion=1.1.50
guavaVersion=21.0
bouncycastleVersion=1.57
Expand Down
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ UNRELEASED
----------
* ``FlowLogic`` now exposes a series of function called ``receiveAll(...)`` allowing to join ``receive(...)`` instructions.

* The ``Cordformation`` gradle plugin has been split into ``cordformation`` and ``cordapp``. The former builds and
deploys nodes for development and testing, the latter turns a project into a cordapp project that generates JARs in
the standard CorDapp format.

* ``Cordform`` and node identity generation
* Cordform may not specify a value for ``NetworkMap``, when that happens, during the task execution the following happens:
1. Each node is started and its signed serialized NodeInfo is written to disk in the node base directory.
Expand Down
6 changes: 3 additions & 3 deletions docs/source/cordapp-build-systems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For example if your Cordapp depends on ``corda-core``, ``your-other-cordapp`` an
JAR will contain all classes and resources from the ``apache-commons`` JAR and its dependencies and *nothing* from the
other two JARs.

.. note:: The rest of this tutorial assumes you are using ``gradle``, the ``cordformation`` plugin and have forked from
.. note:: The rest of this tutorial assumes you are using ``gradle``, the ``cordapp`` plugin and have forked from
one of our cordapp templates.

The ``jar`` task included by default in the cordapp templates will automatically build your JAR in this format as long
Expand All @@ -40,7 +40,7 @@ To make use of the Corda test facilities you must;

.. warning:: Never include ``corda-test-utils`` as a ``compile`` or ``cordaCompile`` dependency.

These configurations work by the ``cordformation`` plugin adding ``cordaCompile`` as a new configuration that ``compile``
These configurations work by the ``cordapp`` plugin adding ``cordaCompile`` as a new configuration that ``compile``
extends from, and ``cordaRuntime`` which ``runtime`` extends from.

Choosing your Corda version
Expand All @@ -57,7 +57,7 @@ can find the latest published version of both here: https://bintray.com/r3/corda

``corda_gradle_plugins_versions`` are given in the form ``major.minor.patch``. You should use the same ``major`` and
``minor`` versions as the Corda version you are using, and the latest ``patch`` version. A list of all the available
versions can be found here: https://bintray.com/r3/corda/cordformation.
versions can be found here: https://bintray.com/r3/corda/cordapp.

In certain cases, you may also wish to build against the unstable Master branch. See :doc:`building-against-master`.

Expand Down
13 changes: 7 additions & 6 deletions docs/source/example-code/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.quasar-utils'

repositories {
Expand Down Expand Up @@ -30,9 +31,9 @@ sourceSets {
compileTestJava.dependsOn tasks.getByPath(':node:capsule:buildCordaJAR')

dependencies {
cordaCompile project(':core')
cordaCompile project(':client:jfx')
cordaCompile project(':node-driver')
compile project(':core')
compile project(':client:jfx')
compile project(':node-driver')
testCompile project(':verifier')
testCompile project(':test-utils')

Expand All @@ -42,11 +43,11 @@ dependencies {
exclude group: "junit"
}

cordaCompile project(path: ":node:capsule", configuration: 'runtimeArtifacts')
cordaCompile project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
compile project(path: ":node:capsule", configuration: 'runtimeArtifacts')
compile project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')

// Corda Plugins: dependent flows and services
cordapp project(':finance')
compile project(':finance')
}

mainClassName = "net.corda.docs.ClientRpcTutorialKt"
Expand Down
2 changes: 1 addition & 1 deletion finance/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'kotlin-jpa'
apply plugin: CanonicalizerPlugin
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'com.jfrog.artifactory'

description 'Corda finance modules'
Expand Down
4 changes: 3 additions & 1 deletion gradle-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
ext.gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
ext.bouncycastle_version = constants.getProperty("bouncycastleVersion")
ext.typesafe_config_version = constants.getProperty("typesafeConfigVersion")
ext.kotlin_version = constants.getProperty("kotlinVersion")

repositories {
mavenLocal()
Expand All @@ -19,6 +20,7 @@ buildscript {
dependencies {
classpath "net.corda.plugins:publish-utils:$gradle_plugins_version"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -39,7 +41,7 @@ bintrayConfig {
projectUrl = 'https://github.com/corda/corda'
gpgSign = true
gpgPassphrase = System.getenv('CORDA_BINTRAY_GPG_PASSPHRASE')
publications = ['cordformation', 'quasar-utils', 'cordform-common', 'api-scanner']
publications = ['cordformation', 'quasar-utils', 'cordform-common', 'api-scanner', 'cordapp']
license {
name = 'Apache-2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0'
Expand Down
10 changes: 10 additions & 0 deletions gradle-plugins/cordapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Cordapp Gradle Plugin

## Purpose

To transform any project this plugin is applied to into a cordapp project that generates a cordapp JAR.

## Effects

Will modify the default JAR task to create a CorDapp format JAR instead [see here](https://docs.corda.net/cordapp-build-systems.html)
for more information.
18 changes: 18 additions & 0 deletions gradle-plugins/cordapp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: 'kotlin'
apply plugin: 'net.corda.plugins.publish-utils'

description 'Turns a project into a cordapp project that produces cordapp fat JARs'

repositories {
mavenCentral()
jcenter()
}

dependencies {
compile gradleApi()
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}

publish {
name project.name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.corda.plugins

import org.gradle.api.*
import org.gradle.api.artifacts.*
import org.gradle.jvm.tasks.Jar
import java.io.File

/**
* The Cordapp plugin will turn a project into a cordapp project which builds cordapp JARs with the correct format
* and with the information needed to run on Corda.
*/
class CordappPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.logger.info("Configuring ${project.name} as a cordapp")

Utils.createCompileConfiguration("cordapp", project)
Utils.createCompileConfiguration("cordaCompile", project)

val configuration: Configuration = project.configurations.create("cordaRuntime")
configuration.isTransitive = false
project.configurations.single { it.name == "runtime" }.extendsFrom(configuration)

configureCordappJar(project)
}

/**
* Configures this project's JAR as a Cordapp JAR
*/
private fun configureCordappJar(project: Project) {
// Note: project.afterEvaluate did not have full dependency resolution completed, hence a task is used instead
val task = project.task("configureCordappFatJar")
val jarTask = project.tasks.single { it.name == "jar" } as Jar
task.doLast {
jarTask.from(getDirectNonCordaDependencies(project).map { project.zipTree(it)}).apply {
exclude("META-INF/*.SF")
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
}
}
jarTask.dependsOn(task)
}

private fun getDirectNonCordaDependencies(project: Project): Set<File> {
project.logger.info("Finding direct non-corda dependencies for inclusion in CorDapp JAR")
val excludes = listOf(
mapOf("group" to "org.jetbrains.kotlin", "name" to "kotlin-stdlib"),
mapOf("group" to "org.jetbrains.kotlin", "name" to "kotlin-stdlib-jre8"),
mapOf("group" to "org.jetbrains.kotlin", "name" to "kotlin-reflect"),
mapOf("group" to "co.paralleluniverse", "name" to "quasar-core")
)

val runtimeConfiguration = project.configuration("runtime")
// The direct dependencies of this project
val excludeDeps = project.configuration("cordapp").allDependencies +
project.configuration("cordaCompile").allDependencies +
project.configuration("cordaRuntime").allDependencies
val directDeps = runtimeConfiguration.allDependencies - excludeDeps
// We want to filter out anything Corda related or provided by Corda, like kotlin-stdlib and quasar
val filteredDeps = directDeps.filter { dep ->
excludes.none { exclude -> (exclude["group"] == dep.group) && (exclude["name"] == dep.name) }
}
filteredDeps.forEach {
// net.corda or com.r3.corda.enterprise may be a core dependency which shouldn't be included in this cordapp so give a warning
if ((it.group.startsWith("net.corda.") || it.group.startsWith("com.r3.corda.enterprise."))) {
project.logger.warn("You appear to have included a Corda platform component ($it) using a 'compile' or 'runtime' dependency." +
"This can cause node stability problems. Please use 'corda' instead." +
"See http://docs.corda.net/cordapp-build-systems.html")
} else {
project.logger.info("Including dependency in CorDapp JAR: $it")
}
}
return filteredDeps.map { runtimeConfiguration.files(it) }.flatten().toSet()
}

private fun Project.configuration(name: String): Configuration = configurations.single { it.name == name }
}
17 changes: 17 additions & 0 deletions gradle-plugins/cordapp/src/main/kotlin/net/corda/plugins/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.corda.plugins

import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration

class Utils {
companion object {
@JvmStatic
fun createCompileConfiguration(name: String, project: Project) {
if(!project.configurations.any { it.name == name }) {
val configuration = project.configurations.create(name)
configuration.isTransitive = false
project.configurations.single { it.name == "compile" }.extendsFrom(configuration)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=net.corda.plugins.CordappPlugin
7 changes: 1 addition & 6 deletions gradle-plugins/cordformation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
buildscript {
// For sharing constants between builds
Properties constants = new Properties()
file("$projectDir/../../constants.properties").withInputStream { constants.load(it) }

ext.kotlin_version = constants.getProperty("kotlinVersion")

repositories {
mavenCentral()
}
Expand Down Expand Up @@ -41,6 +35,7 @@ sourceSets {
dependencies {
compile gradleApi()
compile localGroovy()
compile project(":cordapp")

noderunner "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"

Expand Down
Loading

0 comments on commit 484cf75

Please sign in to comment.