From abf4cc5e54eaf057f0c7bc2d9d17e0bbb815460f Mon Sep 17 00:00:00 2001 From: Tal Moran Date: Wed, 18 Jan 2017 21:54:22 +0200 Subject: [PATCH] Add task to download protoc (protobuf compiler) to root-level build/ directory --- build.gradle | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/build.gradle b/build.gradle index 9f070e3..8c01ae9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,6 @@ +plugins { + id "com.google.osdetector" version "1.4.0" +} subprojects { proj -> proj.afterEvaluate { @@ -8,3 +11,44 @@ subprojects { proj -> } } } + +// Script to create a copy of the protobuf compiler jar in the top-level build directory +// (will make it easier to configure the intellij protobuf plugin) +repositories { + mavenLocal(); + mavenCentral(); +} + + +project.ext.protocLocation = 'com.google.protobuf:protoc:3.+' + +// Copied from Google's protobuf plugin code +File getProtocDep(protocLocation) { + // create a project configuration dependency for the artifact + Configuration config = project.configurations.create("protobufToolsLocator") { + visible = false + transitive = false + extendsFrom = [] + } + + def groupId, artifact, version + (groupId, artifact, version) = protocLocation.split(":") + def notation = [group: groupId, + name: artifact, + version: version, + classifier: project.osdetector.classifier, + ext: 'exe'] + Dependency dep = project.dependencies.add(config.name, notation) + + File file = config.fileCollection(dep).singleFile + + return file +} + + +task getprotoc(type: Copy) { + from getProtocDep(project.ext.protocLocation) + rename { file -> return "protoc" } + into "${buildDir}/" +} +