Skip to content

Commit

Permalink
Introduce Gradle Config DSL (#14)
Browse files Browse the repository at this point in the history
* add kroto configuration gradle dsl

* split up dsl config example into separate file
  • Loading branch information
marcoferrer authored Dec 15, 2019
1 parent dd0a70d commit a7198fc
Show file tree
Hide file tree
Showing 16 changed files with 665 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
- ./gradlew assemble
script:
- ./gradlew check
- cd example-project && ./gradlew test
- cd example-project && ./gradlew test && ./gradlew clean test -PuseKrotoConfigDsl=true
after_success:
- bash <(curl -s https://codecov.io/bash)
92 changes: 52 additions & 40 deletions example-project/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
ext {
versions = [
"protobuf": '3.9.0',
"grpc": '1.23.0',
"kotlin": '1.3.50',
"protobuf" : '3.9.0',
"grpc" : '1.23.0',
"kotlin" : '1.3.50',
"coroutines": '1.3.0',
"krotoplus": '0.6.0-SNAPSHOT'
"krotoplus" : '0.6.0-SNAPSHOT'
]
}

Expand All @@ -14,25 +14,30 @@ buildscript {
mavenCentral()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' }
}

dependencies {
classpath "com.google.protobuf:protobuf-java:${versions.protobuf}"
}
}

plugins{
plugins {
id 'idea'
id 'com.google.protobuf' version '0.8.7'
id 'com.google.protobuf' version '0.8.8'
id "org.jetbrains.kotlin.jvm" version "1.3.50"
id "com.github.marcoferrer.kroto-plus" version "0.6.0-SNAPSHOT"
}

group = 'com.github.marcoferrer.krotoplus'
version = versions.krotoplus

compileKotlin {
kotlinOptions{
kotlinOptions {
jvmTarget = "1.8"
}
}

compileTestKotlin {
kotlinOptions{
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xuse-experimental=kotlin.Experimental"]
}
Expand Down Expand Up @@ -62,8 +67,8 @@ dependencies {
implementation "com.github.marcoferrer.krotoplus:kroto-plus-message:${versions.krotoplus}"

implementation "io.grpc:grpc-protobuf:${versions.grpc}",
"io.grpc:grpc-stub:${versions.grpc}",
"io.grpc:grpc-netty:${versions.grpc}"
"io.grpc:grpc-stub:${versions.grpc}",
"io.grpc:grpc-netty:${versions.grpc}"

testImplementation "io.grpc:grpc-testing:${versions.grpc}"

Expand All @@ -80,41 +85,48 @@ idea {
}
}

protobuf {
protoc { artifact = "com.google.protobuf:protoc:${versions.protobuf}"}

generatedFilesBaseDir = "$buildDir/generated-sources"
if (project.findProperty("useKrotoConfigDsl")?.toBoolean() ?: false) {
// Use experimental kroto plus gradle config
apply from: "krotoPlusConfig.gradle"
} else {

protobuf {
protoc { artifact = "com.google.protobuf:protoc:${versions.protobuf}"}

generatedFilesBaseDir = "$buildDir/generated-sources"

//noinspection GroovyAssignabilityCheck
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${versions.grpc}" }
kroto {
artifact = "com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:${versions.krotoplus}"
//noinspection GroovyAssignabilityCheck
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${versions.grpc}" }
kroto {
artifact = "com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:${versions.krotoplus}"
}
}
}

generateProtoTasks {
def krotoConfig = file("krotoPlusConfig.asciipb")

all().each{ task ->
// Adding the config file to the task inputs lets UP-TO-DATE checks
// include changes to configuration
task.inputs.files krotoConfig

// If we're using precompiled scripts for improved performance then we
// should depend on the jar task for our scripts
task.dependsOn ':kp-scripts:jar'

task.plugins {
grpc { outputSubDir = "java" }
kroto {
// The extendable-messages generator needs the outputSubDir
// to be the same as 'task.builtins.java.outputSubDir' since
// it relies on the insertion_point api from protoc.
outputSubDir = "java"
option "ConfigPath=$krotoConfig"
generateProtoTasks {
def krotoConfig = file("krotoPlusConfig.asciipb")

all().each{ task ->
// Adding the config file to the task inputs lets UP-TO-DATE checks
// include changes to configuration
task.inputs.files krotoConfig

// If we're using precompiled scripts for improved performance then we
// should depend on the jar task for our scripts
task.dependsOn ':kp-scripts:jar'

task.plugins {
grpc { outputSubDir = "java" }
kroto {
// The extendable-messages generator needs the outputSubDir
// to be the same as 'task.builtins.java.outputSubDir' since
// it relies on the insertion_point api from protoc.
outputSubDir = "java"
option "ConfigPath=$krotoConfig"
}
}
}
}
}
}
}
112 changes: 112 additions & 0 deletions example-project/krotoPlusConfig.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

apply plugin: "com.github.marcoferrer.kroto-plus"

krotoPlus {
config {
//noinspection GroovyAssignabilityCheck
main {
mockServices {
filter {
addIncludePath("jojo/*")
}
implementAsObject = true
generateServiceList = true
serviceListPackage = "jojo.bizarre.adventure"
serviceListName = "MockJojoServices"
}

mockServices {
filter {
addIncludePath("test/message/*")
}
implementAsObject = true
generateServiceList = true
serviceListPackage = "test.message"
}

protoBuilders {
filter {
addExcludePath("google/*")
}
unwrapBuilders = true
useDslMarkers = true
}

grpcStubExts {
supportCoroutines = true
}
grpcCoroutines()
extendableMessages {
filter {
addIncludePath("jojo/bizarre/adventure/stand/*")
}
}
generatorScripts {
addScriptPath("helloThere.kts")
scriptBundle = file("kp-scripts/build/libs/kp-scripts.jar")
}
generatorScripts {
addScriptPath("varArgExtensionGenerator.kts")
scriptBundle = file("kp-scripts/build/libs/kp-scripts.jar")
}
insertions {
filter {
addIncludePath("jojo/bizarre/adventure/character/*")
}
entry {
point = 'MESSAGE_IMPLEMENTS'
addScriptPath "extendableMessages.kts"
scriptBundle = file("kp-scripts/build/libs/kp-scripts.jar")
}
entry {
point = 'BUILDER_IMPLEMENTS'
addScriptPath "extendableMessages.kts"
scriptBundle = file("kp-scripts/build/libs/kp-scripts.jar")
}
entry {
point = 'CLASS_SCOPE'
addScriptPath "extendableMessages.kts"
scriptBundle = file("kp-scripts/build/libs/kp-scripts.jar")
}
entry {
point = 'OUTER_CLASS_SCOPE'
addScriptPath(file("kp-scripts/src/main/kotlin/sampleInsertionScript.kts").toString())
}
}
}
}

}

protobuf {
protoc { artifact = "com.google.protobuf:protoc:${versions.protobuf}" }

generatedFilesBaseDir = "$buildDir/generated-sources"

//noinspection GroovyAssignabilityCheck
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${versions.grpc}" }
kroto {
artifact = "com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:${versions.krotoplus}"
}
}

generateProtoTasks {
all().each { task ->
// If we're using precompiled scripts for improved performance then we
// should depend on the jar task for our scripts
task.dependsOn ':kp-scripts:jar'

task.plugins {
grpc { outputSubDir = "java" }
kroto {
// The extendable-messages generator needs the outputSubDir
// to be the same as 'task.builtins.java.outputSubDir' since
// it relies on the insertion_point api from protoc.
outputSubDir = "java"
option krotoPlus.config.main.asOption()
}
}
}
}
}
12 changes: 12 additions & 0 deletions example-project/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ pluginManagement{
jcenter()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' }
maven { url 'https://plugins.gradle.org/m2/' }

flatDir dirs: "${rootDir}/../kroto-plus-gradle-plugin/build/libs/"
}

// Only needed for local gradle plugin development
resolutionStrategy {
eachPlugin {
if(requested.id.id == "com.github.marcoferrer.kroto-plus"){
useModule("com.github.marcoferrer.krotoplus:kroto-plus-gradle-plugin:${requested.version}")
}
}
}
}

include 'kp-scripts'
28 changes: 19 additions & 9 deletions kroto-plus-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ apply from: "$rootDir/publishing.gradle"

def pluginId = 'com.github.marcoferrer.kroto-plus'

repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.gradle.org/gradle/libs-releases-local/" }
google()
// Needed for resolving 'kotlinx-metadata-jvm'
// A transitive dependency of gradle Kotlin DSL
maven { url "https://kotlin.bintray.com/kotlinx/" }
}

gradlePlugin {
plugins {
krotoPlusPlugin {
Expand All @@ -17,6 +26,11 @@ gradlePlugin {

dependencies{
implementation "com.google.protobuf:protobuf-java:${Versions.protobuf}"
compileOnly gradleApi()
compileOnly "org.gradle:gradle-kotlin-dsl:1.0.4"
compileOnly "com.google.protobuf:protobuf-gradle-plugin:0.8.8"
compileOnly 'com.google.gradle:osdetector-gradle-plugin:1.6.2'
compileOnly project(":protoc-gen-kroto-plus")
protobuf project(":protoc-gen-kroto-plus")
}

Expand All @@ -30,7 +44,7 @@ pluginBundle {
krotoPlusPlugin {
id = pluginId
displayName = 'Kroto+ Config Plugin'
description = 'Protoc plugin for bringing together Kotlin, Protobuf, Coroutines, and gRPC'
description = 'gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc'
tags = [ 'coroutines', 'kotlin', 'grpc', 'protobuf','protocol-buffers', 'code-generation' ]
}
}
Expand All @@ -50,14 +64,10 @@ protobuf {
generateProtoTasks {
def krotoConfig = file("krotoPlusConfig.asciipb")

all().each { task ->
task.inputs.files krotoConfig
task.dependsOn ':protoc-gen-kroto-plus:buildCanteenArtifacts'
task.plugins {
kroto {
outputSubDir = "java"
}
}
all().each{ task ->
task.dependsOn ':kroto-plus-gradle-plugin:gen-config-dsl:jar'
configProtoTaskWithKroto(task, krotoConfig)
}
}

}
28 changes: 28 additions & 0 deletions kroto-plus-gradle-plugin/gen-config-dsl/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019 Kroto+ Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

dependencies{
implementation project(":protoc-gen-kroto-plus")
implementation "com.google.protobuf:protobuf-java:3.6.1"
implementation "org.jetbrains.kotlin:kotlin-script-util"
implementation ("com.squareup:kotlinpoet:0.7.0") {
exclude group: 'org.jetbrains.kotlin'
}
}

jar {
archiveName = 'bundle.jar'
}
Loading

0 comments on commit a7198fc

Please sign in to comment.