forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CORDA-686 - Split Cordapp gradle plugin from cordformation (corda#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.
- Loading branch information
Showing
23 changed files
with
167 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
76 changes: 76 additions & 0 deletions
76
gradle-plugins/cordapp/src/main/kotlin/net/corda/plugins/CordappPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
gradle-plugins/cordapp/src/main/kotlin/net/corda/plugins/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/cordapp/src/main/resources/META-INF/gradle-plugins/net.corda.plugins.cordapp.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
implementation-class=net.corda.plugins.CordappPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.