Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
169 changes: 54 additions & 115 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
final String CREDENTIALS_LOCATION = 'credentials.properties';

project.ext {
// NOTE: when updating Protobuf dependency, please check that KnownTypes.addStandardProtobufTypes() method
// is updated with new Message types introduced in the new version of Protobuf.
PROTOBUF_VERSION = '3.0.0-beta-3'
PROTOBUF_DEPENDENCY = "com.google.protobuf:protoc:${PROTOBUF_VERSION}"
GRPC_VERSION = '0.14.0'
SLF4J_VERSION = '1.7.21'

SPINE_PROTOBUF_PLUGIN_ID = 'org.spine3.tools.protobuf-plugin'
PUBLISH_PLUGIN_PATH = "$projectDir/gradle/plugins/publish.gradle"

CREDENTIALS_FILE_PATH = 'credentials.properties'
PROJECTS_TO_PUBLISH = ["client", "server", "values", "testutil"]
}

buildscript {
repositories {
mavenCentral()
mavenLocal()
maven {
url = 'http://maven.teamdev.com/repository/spine'
}
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.7'
classpath group: 'com.google.protobuf', name:'protobuf-gradle-plugin', version: '0.7.7'
classpath group: 'org.spine3.tools', name: 'protobuf-plugin', version: '1.4.8', changing: true
}
configurations.all({
resolutionStrategy.cacheChangingModulesFor(0, 'seconds')
})
}

allprojects {
Expand All @@ -19,44 +40,32 @@ allprojects {
version = '0.5.1-SNAPSHOT'
}

project.ext {
// NOTE: when updating Protobuf dependency, please check that KnownTypes.addStandardProtobufTypes() method
// is updated with new Message types introduced in the new version of Protobuf.
PROTOBUF_VERSION = '3.0.0-beta-3';
PROTOBUF_DEPENDENCY = "com.google.protobuf:protoc:${project.PROTOBUF_VERSION}";
MAVEN_REPOSITORY_URL = 'http://maven.teamdev.com/repository/spine';
SPINE_PROTOBUF_PLUGIN_VERSION = "1.4.8"
GRPC_VERSION = '0.14.0'
SLF4J_VERSION = '1.7.21'
}
subprojects {

def repositoryUserName = null;
def repositoryUserPassword = null;
final Properties properties = new Properties();
final File credentialsFile = file(CREDENTIALS_LOCATION);
if (credentialsFile.exists()) {
properties.load(credentialsFile.newDataInputStream());
repositoryUserName = properties.getProperty("user.name");
repositoryUserPassword = properties.getProperty("user.password");
}
project.ext {
SRC_DIR = "$projectDir/src"
GEN_DIR = "$projectDir/generated"

subprojects {
GEN_MAIN_JAVA_DIR = "$GEN_DIR/main/java"
GEN_TEST_JAVA_DIR = "$GEN_DIR/test/java"

buildscript {
repositories {
mavenLocal()
maven {
url = project.MAVEN_REPOSITORY_URL
}
mavenCentral()
}
GEN_MAIN_GRPC_DIR = "$GEN_DIR/main/grpc"
GEN_TEST_GRPC_DIR = "$GEN_DIR/test/grpc"

GEN_MAIN_SPINE_DIR = "$GEN_DIR/main/spine"

TEST_ARTIFACTS_PLUGIN_PATH = '../gradle/plugins/test-artifacts.gradle'
GEN_DESCRIPTOR_SET_PLUGIN_PATH = '../gradle/plugins/generate-descriptor-set.gradle'
GRPC_PLUGIN_PATH = '../gradle/plugins/grpc.gradle'
JACOCO_PLUGIN_PATH = '../gradle/plugins/jacoco.gradle'
}

apply plugin: 'java';
apply plugin: 'com.google.protobuf';
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
apply from: JACOCO_PLUGIN_PATH

sourceCompatibility = 1.7;
targetCompatibility = 1.7;
sourceCompatibility = 1.7
targetCompatibility = 1.7

// Set Java home to point to JDK7 in gradle.properties file.
//
Expand All @@ -68,7 +77,6 @@ subprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}

dependencies {
Expand All @@ -88,24 +96,19 @@ subprojects {
exclude(module: 'hamcrest-core')
}
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testCompile 'org.mockito:mockito-core:2.+'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.+'
}

final String SRC_ROOT_DIR = "$projectDir/src";
final String GEN_ROOT_DIR = "$projectDir/generated";
final String GEN_MAIN_JAVA_DIR = "${GEN_ROOT_DIR}/main/java";
final String GEN_TEST_JAVA_DIR = "${GEN_ROOT_DIR}/test/java";

sourceSets {
main {
proto.srcDirs = ["${SRC_ROOT_DIR}/main/proto"]
java.srcDirs = [GEN_MAIN_JAVA_DIR, "${SRC_ROOT_DIR}/main/java"]
resources.srcDirs = ["${GEN_ROOT_DIR}/main/resources"]
proto.srcDirs = ["$SRC_DIR/main/proto"]
java.srcDirs = [GEN_MAIN_JAVA_DIR, "$SRC_DIR/main/java"]
resources.srcDirs = ["$GEN_DIR/main/resources"]
}
test {
proto.srcDirs = ["${SRC_ROOT_DIR}/test/proto"]
java.srcDirs = [GEN_TEST_JAVA_DIR, "${SRC_ROOT_DIR}/test/java"]
resources.srcDirs = ["${GEN_ROOT_DIR}/test/resources"]
proto.srcDirs = ["$SRC_DIR/test/proto"]
java.srcDirs = [GEN_TEST_JAVA_DIR, "$SRC_DIR/test/java"]
resources.srcDirs = ["$GEN_DIR/test/resources"]
}
}

Expand All @@ -115,7 +118,7 @@ subprojects {
artifact = "io.grpc:protoc-gen-grpc-java:$GRPC_VERSION"
}
}
generatedFilesBaseDir = GEN_ROOT_DIR
generatedFilesBaseDir = GEN_DIR
protoc {
artifact = project.PROTOBUF_DEPENDENCY
}
Expand All @@ -131,15 +134,6 @@ subprojects {
classifier "test"
}

jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}

check.dependsOn jacocoTestReport

idea.module.iml {
beforeMerged { final module ->
module.dependencies.clear()
Expand All @@ -150,8 +144,8 @@ subprojects {
}

idea.module {
generatedSourceDirs += file(GEN_MAIN_JAVA_DIR);
testSourceDirs += file(GEN_TEST_JAVA_DIR);
generatedSourceDirs += file(GEN_MAIN_JAVA_DIR)
testSourceDirs += file(GEN_TEST_JAVA_DIR)
}
}

Expand All @@ -166,59 +160,4 @@ idea.project.ipr {
}
}

task readPublishingCredentials << {
if (repositoryUserName == null || repositoryUserPassword == null) {
throw new InvalidUserDataException("Please set up valid credentials. " +
"Credentials should be set in ${CREDENTIALS_LOCATION} file in the project\'s root.");
}
println "Publishing build as ${repositoryUserName}";
}

task publish << {}

void dependPublish(final Project project) {
final Set<Task> credentialsTasks = getTasksByName("readPublishingCredentials", false);
project.getTasksByName("publish", false).each { final task ->
task.dependsOn credentialsTasks;
}
publish.dependsOn project.getTasksByName("publish", false);
}

// Artifacts to publish
final def publishingProjects = ["client", "server", "values", "testutil"];

publishingProjects.each {
project(":$it") { final currentProject ->

apply plugin: 'maven-publish';

publishing {
publications {
mavenJava(MavenPublication) {
groupId = "${group}";
artifactId = "${currentProject.name}";
version = "${currentProject.version}";

from components.java;

artifact sourceJar;
artifact testOutputJar;
}
}
}

publishing {
repositories {
maven {
credentials {
username = "${repositoryUserName}";
password = "${repositoryUserPassword}";
}
url = project.MAVEN_REPOSITORY_URL;
}
}
}

dependPublish(project);
}
}
apply from: PUBLISH_PLUGIN_PATH
53 changes: 7 additions & 46 deletions client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,53 +1,14 @@
buildscript {
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
classpath group: 'org.spine3.tools', name: 'protobuf-plugin', version: "$SPINE_PROTOBUF_PLUGIN_VERSION", changing: true
}
}

dependencies {
compile group: 'io.grpc', name: 'grpc-okhttp', version: "$GRPC_VERSION"
compile group: 'io.grpc', name: 'grpc-protobuf', version: "$GRPC_VERSION"
compile group: 'io.grpc', name: 'grpc-stub', version: "$GRPC_VERSION"
compile group: 'io.grpc', name: 'grpc-okhttp', version: GRPC_VERSION
compile group: 'io.grpc', name: 'grpc-protobuf', version: GRPC_VERSION
compile group: 'io.grpc', name: 'grpc-stub', version: GRPC_VERSION

testCompile project(path: ":testutil", configuration: 'testArtifacts')
testCompile project(path: ":testutil")
}

apply plugin: 'org.spine3.tools.protobuf-plugin';
apply from: GRPC_PLUGIN_PATH

sourceSets {
main {
proto {
srcDirs += ["${project(":client").projectDir}/src/main/proto"]
}
java {
srcDir "$projectDir/generated/main/grpc"
}
}
}
apply from: TEST_ARTIFACTS_PLUGIN_PATH

protobuf {
generateProtoTasks {
all().each { final task ->
task.plugins {
grpc {}
}
}
}
}

// required for usage of test classes from other modules
configurations {
testArtifacts.extendsFrom testRuntime
}

task testJar(type: Jar) {
classifier "test"
from sourceSets.test.output
}

artifacts {
testArtifacts testJar
}
apply plugin: SPINE_PROTOBUF_PLUGIN_ID
38 changes: 5 additions & 33 deletions examples/build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
buildscript {
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
classpath group: 'org.spine3.tools', name: 'protobuf-plugin', version: "$SPINE_PROTOBUF_PLUGIN_VERSION", changing: true
}
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile project(path: ":client", configuration: 'testArtifacts')
testCompile project(path: ":server", configuration: 'testArtifacts')

compile project(path: ':client');
compile project(path: ':server');
compile project(path: ':client')
compile project(path: ':server')
}

sourceSets {
main {
java {
srcDir "$projectDir/generated/main/spine"
}
}
}
sourceSets.main.java.srcDir GEN_MAIN_SPINE_DIR

protobuf {
generateProtoTasks {
all().each { final task ->
task.plugins {
task.generateDescriptorSet = true
task.descriptorSetOptions.path = "${projectDir}/build/descriptors/${task.sourceSet.name}.desc"
task.descriptorSetOptions.includeImports = true
}
}
}
}
apply from: GEN_DESCRIPTOR_SET_PLUGIN_PATH

apply plugin: 'org.spine3.tools.protobuf-plugin';
apply plugin: SPINE_PROTOBUF_PLUGIN_ID
33 changes: 33 additions & 0 deletions gradle/plugins/generate-descriptor-set.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2016, TeamDev Ltd. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* 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.
*/

// Apply this script if it is needed to generate Protobuf descriptor set (special files with `.desc` extension).
// These files may be needed by Gradle plugins to obtain descriptors of `.proto` files of this project.
protobuf {
generateProtoTasks {
all().each { final task ->
task.plugins {
task.generateDescriptorSet = true
task.descriptorSetOptions.path = "$projectDir/build/descriptors/${task.sourceSet.name}.desc"
task.descriptorSetOptions.includeImports = true
}
}
}
}
Loading