CORDA-686 - Split Cordapp gradle plugin from cordformation (#1817)

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.
This commit is contained in:
Clinton 2017-10-09 20:08:08 +01:00 committed by GitHub
parent 747830ff90
commit 484cf75420
23 changed files with 167 additions and 92 deletions

4
.idea/compiler.xml generated
View File

@ -2,6 +2,8 @@
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8">
<module name="api-scanner_main" target="1.8" />
<module name="api-scanner_test" target="1.8" />
<module name="attachment-demo_integrationTest" target="1.8" />
<module name="attachment-demo_main" target="1.8" />
<module name="attachment-demo_test" target="1.8" />
@ -19,6 +21,8 @@
<module name="corda-webserver_integrationTest" target="1.8" />
<module name="corda-webserver_main" target="1.8" />
<module name="corda-webserver_test" target="1.8" />
<module name="cordapp_main" target="1.8" />
<module name="cordapp_test" target="1.8" />
<module name="cordform-common_main" target="1.8" />
<module name="cordform-common_test" target="1.8" />
<module name="cordformation_main" target="1.8" />

View File

@ -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"
@ -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')
}

View File

@ -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"

View File

@ -1,4 +1,4 @@
gradlePluginsVersion=1.1.2
gradlePluginsVersion=2.0.0
kotlinVersion=1.1.50
guavaVersion=21.0
bouncycastleVersion=1.57

View File

@ -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.

View File

@ -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
@ -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
@ -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`.

View File

@ -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 {
@ -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')
@ -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"

View File

@ -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'

View File

@ -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()
@ -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"
}
}
@ -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'

View File

@ -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.

View File

@ -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
}

View File

@ -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 }
}

View File

@ -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)
}
}
}
}

View File

@ -0,0 +1 @@
implementation-class=net.corda.plugins.CordappPlugin

View File

@ -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()
}
@ -41,6 +35,7 @@ sourceSets {
dependencies {
compile gradleApi()
compile localGroovy()
compile project(":cordapp")
noderunner "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"

View File

@ -9,40 +9,6 @@ import org.gradle.api.artifacts.Configuration
* testing, and debugging. It will prepopulate several fields in the configuration and create a simple node runner.
*/
class Cordformation implements Plugin<Project> {
void apply(Project project) {
createCompileConfiguration("cordapp", project)
createCompileConfiguration("cordaCompile", project)
Configuration configuration = project.configurations.create("cordaRuntime")
configuration.transitive = false
project.configurations.runtime.extendsFrom configuration
configureCordappJar(project)
}
private void createCompileConfiguration(String name, Project project) {
Configuration configuration = project.configurations.create(name)
configuration.transitive = false
project.configurations.compile.extendsFrom configuration
}
/**
* Configures this project's JAR as a Cordapp JAR
*/
private void configureCordappJar(Project project) {
// Note: project.afterEvaluate did not have full dependency resolution completed, hence a task is used instead
def task = project.task('configureCordappFatJar') {
doLast {
project.tasks.jar.from(getDirectNonCordaDependencies(project).collect { project.zipTree(it)}) {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
}
}
project.tasks.jar.dependsOn task
}
/**
* Gets a resource file from this plugin's JAR file.
*
@ -56,31 +22,7 @@ class Cordformation implements Plugin<Project> {
}, filePathInJar).asFile()
}
private static Set<File> getDirectNonCordaDependencies(Project project) {
def excludes = [
[group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib'],
[group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8'],
[group: 'org.jetbrains.kotlin', name: 'kotlin-reflect'],
[group: 'co.paralleluniverse', name: 'quasar-core']
]
project.with {
// The direct dependencies of this project
def excludeDeps = configurations.cordapp.allDependencies + configurations.cordaCompile.allDependencies + configurations.cordaRuntime.allDependencies
def directDeps = configurations.runtime.allDependencies - excludeDeps
// We want to filter out anything Corda related or provided by Corda, like kotlin-stdlib and quasar
def filteredDeps = directDeps.findAll { excludes.collect { exclude -> (exclude.group == it.group) && (exclude.name == it.name) }.findAll { it }.isEmpty() }
filteredDeps.each {
// 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 && (it.group.startsWith('net.corda.') || it.group.startsWith('com.r3.corda.enterprise.'))) {
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 {
logger.info("Including dependency in CorDapp JAR: $it")
}
}
return filteredDeps.collect { configurations.runtime.files it }.flatten().toSet()
}
void apply(Project project) {
Utils.createCompileConfiguration("cordapp", project)
}
}

View File

@ -4,3 +4,4 @@ include 'quasar-utils'
include 'cordformation'
include 'cordform-common'
include 'api-scanner'
include 'cordapp'

View File

@ -3,6 +3,7 @@ apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'

View File

@ -3,6 +3,7 @@ apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'

View File

@ -3,6 +3,7 @@ apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'
apply plugin: 'application'

View File

@ -5,6 +5,7 @@ apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'

View File

@ -7,6 +7,7 @@ apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'

View File

@ -3,6 +3,7 @@ apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'