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

Kotlin dsl support #262

Merged
merged 36 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0e47250
fix error in ide highlighting
marcoferrer Aug 23, 2018
2865946
add kotlin dsl dependency to build
marcoferrer Aug 23, 2018
9600995
add initial interop extensions
marcoferrer Aug 23, 2018
32b3d53
added exts for different task collection types
marcoferrer Aug 23, 2018
4de07b1
added kotlin dsl example
marcoferrer Aug 24, 2018
995569c
added dependency configuration exts
marcoferrer Aug 24, 2018
32836af
apply kotlin style guide linting
marcoferrer Oct 5, 2018
3e5fc62
move default example project
marcoferrer Oct 5, 2018
26549e1
add example kotlin dsl project
marcoferrer Oct 5, 2018
d4002f7
bump kotlin version
marcoferrer Oct 5, 2018
c63bcc7
bump gradle wrapper version 4.10
marcoferrer Oct 5, 2018
7430894
remove old settings.gradle for example
marcoferrer Oct 5, 2018
c71d47a
align kotlin version with version used kotlin gradle dsl
marcoferrer Oct 11, 2018
e76a6fc
revert project gradle wrapper to 4.8
marcoferrer Oct 11, 2018
f39687f
add support for custom configuration dependency management
marcoferrer Oct 12, 2018
3d87af8
split up configurator exts and default dependency exts
marcoferrer Oct 12, 2018
9c53657
add support for source directory set configuration
marcoferrer Oct 12, 2018
c858b03
update example script with source directory set configuration
marcoferrer Oct 12, 2018
cdae1bd
update example script with custom configuration dependency
marcoferrer Oct 12, 2018
16234e5
refactor default configurations to use dependency helper interface
marcoferrer Oct 14, 2018
aaa295e
update example with plugins block and roll back kotlin version
marcoferrer Oct 15, 2018
831a355
clean up dependency helper and switch to source set name utils
marcoferrer Oct 15, 2018
5ee5d3b
remove custom source set dependency helper
marcoferrer Oct 16, 2018
89fd766
update sample ktdsl project config
marcoferrer Oct 16, 2018
5a96a1b
add kotlin dsl test project
marcoferrer Oct 16, 2018
ae2e090
add kotlin dsl tests
marcoferrer Oct 16, 2018
de27e56
clean up build script
marcoferrer Oct 16, 2018
96c0635
add explicit imports
marcoferrer Oct 16, 2018
00d0a0b
remove redundant kotlin dsl import
marcoferrer Oct 16, 2018
92da1d1
move verifyProjectDirHelper to ProtobufPluginTestHelper
marcoferrer Oct 16, 2018
61c8829
remove usage of non public api in test build script
marcoferrer Oct 18, 2018
0fc32d8
add gradle wrapper with version 4.10 to example project
marcoferrer Oct 18, 2018
35c7ae1
update example links in readme
marcoferrer Oct 18, 2018
c98ece1
revert gradle wrapper and clean up test ktdsl build script
marcoferrer Oct 18, 2018
8b7668c
Update readme
zpencer Oct 18, 2018
d6c0635
fix line endings in gradlew files
marcoferrer Oct 18, 2018
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
18 changes: 17 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ apply plugin: 'codenarc'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'groovy'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'com.jfrog.bintray'
Expand All @@ -31,11 +32,13 @@ buildscript {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath "com.gradle.publish:plugin-publish-plugin:0.9.7"
classpath "com.github.ben-manes:gradle-versions-plugin:0.12.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.60"
}
}

repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.gradle.org/gradle/libs-releases-local/" }
google()
}

Expand Down Expand Up @@ -65,6 +68,8 @@ task createClasspathManifest {
dependencies {
compileOnly gradleApi()
compileOnly localGroovy()
compileOnly "org.gradle:gradle-kotlin-dsl:1.0-rc-3"

compile 'com.google.guava:guava:18.0'
compile 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
compile 'commons-lang:commons-lang:2.6'
Expand All @@ -78,7 +83,7 @@ dependencies {
}
testCompile 'commons-io:commons-io:2.5'

testProjectRuntime "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0"
testProjectRuntime "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.60"

// Add android plugin to the test classpath, so that we can jump into class definitions,
// read their sources, set break points, etc while debugging android unit tests.
Expand Down Expand Up @@ -222,3 +227,14 @@ if (System.env.TRAVIS == 'true') {
}
}
}

// Required in order to support building a mixed kotlin/groovy project. With out this,
// we would get a cyclic dependency error, since both compileKotlin and compileGroovy
// depend on compileJava.
// https://discuss.gradle.org/t/kotlin-groovy-and-java-compilation/14903/10
project.afterEvaluate {
compileGroovy.dependsOn = compileGroovy.taskDependencies.mutableValues - 'compileJava'
compileKotlin.dependsOn compileGroovy
compileKotlin.classpath += files(compileGroovy.destinationDir)
classes.dependsOn compileKotlin
}
91 changes: 91 additions & 0 deletions examples/exampleKotlinDslProject/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import com.google.protobuf.gradle.*
import org.gradle.kotlin.dsl.provider.gradleKotlinDslOf

// A minimal example Java project that uses the protobuf plugin.
// To build it:
// $ ../gradlew clean build

buildscript {
repositories {
maven("https://plugins.gradle.org/m2/")
}
dependencies {
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.7-SNAPSHOT")
}

// ********************************************************************************* //
// TODO: Remove after snapshot publish
// We add the root projects output directory as a repo
// since the snapshot is not published yet.
repositories {
flatDir{
dir("$projectDir/../../build/libs/")
}
}
dependencies {
// We have to explicitly add the plugin dependencies to the classpath
// since we are using a local artifact here.
classpath("com.google.gradle:osdetector-gradle-plugin:1.6.0")
classpath("com.google.guava:guava:18.0")
classpath("com.google.gradle:osdetector-gradle-plugin:1.4.0")
classpath("commons-lang:commons-lang:2.6")
}
// ********************************************************************************* //
}

plugins {
java
idea
}

apply(plugin = "com.google.protobuf")

repositories {
maven("https://plugins.gradle.org/m2/" )
}

dependencies {
compile("com.google.protobuf:protobuf-java:3.6.1")
compile("io.grpc:grpc-stub:1.15.1")
compile("io.grpc:grpc-protobuf:1.15.1")
if (JavaVersion.current().isJava9Compatible) {
// Workaround for @javax.annotation.Generated
// see: https://github.com/grpc/grpc-java/issues/3633
compile("javax.annotation:javax.annotation-api:1.3.1")
}
// Extra proto source files besides the ones residing under
// "src/main".
protobuf(files("lib/protos.tar.gz"))
protobuf(fileTree("ext/"))

testCompile("junit:junit:4.12")
// Extra proto source files for test besides the ones residing under
// "src/test".
testProtobuf(files("lib/protos-test.tar.gz"))
}

protobuf {
protoc {
// The artifact spec for the Protobuf Compiler
artifact = "com.google.protobuf:protoc:3.6.1"
}
plugins {
// Optional: an artifact spec for a protoc plugin, with "grpc" as
// the identifier, which can be referred to in the "plugins"
// container of the "generateProtoTasks" closure.
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:1.15.1"
}
}
generateProtoTasks {
ofSourceSet("main").forEach{
it.plugins {
// Apply the "grpc" plugin whose spec is defined above, without
// options. Note the braces cannot be omitted, otherwise the
// plugin will not be added. This is because of the implicit way
// NamedDomainObjectContainer binds the methods.
id("grpc")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rootProject.name = "exampleProject"

File renamed without changes.
9 changes: 9 additions & 0 deletions examples/exampleProject/ext/more.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

message MoreMsg {
string bar = 1;
}

message Foo {
string stuff = 1;
}
12 changes: 12 additions & 0 deletions examples/exampleProject/ext/test1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Created with IntelliJ IDEA.
* User: aantonov
* Date: 1/17/13
* Time: 3:44 PM
* To change this template use File | Settings | File Templates.
*/
syntax = "proto3";

message Test1Msg {
string bar = 1;
}
5 changes: 5 additions & 0 deletions examples/exampleProject/ext/test2.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

message Test2Msg {
string bar = 1;
}
Binary file added examples/exampleProject/lib/protos-test.tar.gz
Binary file not shown.
Binary file added examples/exampleProject/lib/protos.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions examples/exampleProject/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "exampleProject"
28 changes: 28 additions & 0 deletions examples/exampleProject/src/main/java/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import com.google.protobuf.MessageLite;

import java.util.ArrayList;
import java.util.List;

public class Foo {
public static List<MessageLite> getDefaultInstances() {
ArrayList<MessageLite> list = new ArrayList<MessageLite>();
// from src/main/proto/test.proto
list.add(ws.antonov.protobuf.test.Test.TestMessage.getDefaultInstance());
list.add(ws.antonov.protobuf.test.Test.AnotherMessage.getDefaultInstance());
list.add(ws.antonov.protobuf.test.Test.Item.getDefaultInstance());
list.add(ws.antonov.protobuf.test.Test.DataMap.getDefaultInstance());
// from src/main/proto/sample.proto (java_multiple_files == true, thus no outter class)
list.add(com.example.tutorial.Msg.getDefaultInstance());
list.add(com.example.tutorial.SecondMsg.getDefaultInstance());
// from lib/protos.tar.gz/stuff.proto
list.add(Stuff.Blah.getDefaultInstance());
// from ext/more.proto
list.add(More.MoreMsg.getDefaultInstance());
list.add(More.Foo.getDefaultInstance());
// from ext/test1.proto
list.add(Test1.Test1Msg.getDefaultInstance());
// from ext/test2.proto
list.add(Test2.Test2Msg.getDefaultInstance());
return list;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

option java_package = "com.example.tutorial";
option java_outer_classname = "OuterSample";
option java_multiple_files = true;


message Msg {
string foo = 1;
SecondMsg blah = 2;
}

message SecondMsg {
int32 blah = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto2";

package grpc.testing;

option java_package = "com.google.protobuf";
option java_outer_classname = "EmptyProtos";

// An empty message that you can re-use to avoid defining duplicated empty
// messages in your project. A typical example is to use it as argument or the
// return value of a service API. For instance:
//
// service Foo {
// rpc Bar (grpc.testing.Empty) returns (grpc.testing.Empty) { };
// };
//
message Empty {}
Loading