mucking around trying to get protoc working. I've finally got a task that downloads the exe...
This commit is contained in:
parent
ebba0bb767
commit
106d7a7923
12 changed files with 982 additions and 53 deletions
159
modules/protoc-gradle-plugin/build.gradle.kts
Normal file
159
modules/protoc-gradle-plugin/build.gradle.kts
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
import org.gradle.nativeplatform.platform.internal.ArchitectureInternal
|
||||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.5.31"
|
||||
`kotlin-dsl`
|
||||
`java-gradle-plugin`
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("Protobuf & Gradle") {
|
||||
id = "dev-adamko.pb-and-g"
|
||||
implementationClass = "dev.adamko.gradle.pbandg.ProtocPluginKt"
|
||||
description =
|
||||
"Protobuf & Gradle. Wrapper for protoc to generate code from Proto Buffer files."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val protocConfiguration: Configuration by configurations.creating {
|
||||
// A configuration meant for consumers that need the implementation of this component
|
||||
isCanBeResolved = true
|
||||
isCanBeConsumed = false
|
||||
}
|
||||
|
||||
val protobufVersion = "3.19.0"
|
||||
val protocVersion = "3.9.2"
|
||||
|
||||
dependencies {
|
||||
implementation(platform("com.google.protobuf:protobuf-bom:$protobufVersion"))
|
||||
|
||||
implementation("com.google.protobuf:protobuf-java:$protobufVersion")
|
||||
implementation("com.google.protobuf:protobuf-javalite:$protobufVersion")
|
||||
implementation("com.google.protobuf:protobuf-kotlin-lite:$protobufVersion")
|
||||
implementation("com.google.protobuf:protobuf-kotlin:$protobufVersion")
|
||||
implementation("com.google.protobuf:protoc:$protobufVersion")
|
||||
|
||||
implementation(platform("io.grpc:grpc-bom:1.41.0"))
|
||||
implementation("io.grpc:grpc-stub:1.41.0")
|
||||
implementation("io.grpc:grpc-protobuf:1.41.0")
|
||||
|
||||
implementation("io.grpc:grpc-kotlin-stub:1.2.0")
|
||||
implementation("io.grpc:protoc-gen-grpc-kotlin:1.2.0")
|
||||
|
||||
implementation("javax.annotation:javax.annotation-api:1.3.2")
|
||||
//
|
||||
|
||||
// implementation(npm("protoc-gen-ts", "0.15.0"))
|
||||
|
||||
implementation(
|
||||
group = "com.google.protobuf",
|
||||
name = "protoc",
|
||||
version = "3.9.2",
|
||||
// configuration = "",
|
||||
classifier = "windows-x86_64",
|
||||
ext = "exe",
|
||||
)
|
||||
|
||||
protocConfiguration(
|
||||
group = "com.google.protobuf",
|
||||
name = "protoc",
|
||||
version = protocVersion,
|
||||
// configuration = "",
|
||||
classifier = "windows-x86_64",
|
||||
ext = "exe",
|
||||
)
|
||||
|
||||
// protocConfiguration("com.google.protobuf:protoc:3.9.2@exe")
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// https://github.com/protocolbuffers/protobuf/tree/master/protoc-artifacts
|
||||
// The name of a published protoc artifact is in the format:
|
||||
// protoc-<version>-<os>-<arch>.exe
|
||||
// e.g., protoc-3.6.1-linux-x86_64.exe
|
||||
// Note that artifacts for Linux/macOS also have the .exe suffix, but they are not windows binaries.
|
||||
val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
|
||||
val arch: ArchitectureInternal = DefaultNativePlatform.getCurrentArchitecture()
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
// ivy {
|
||||
// url = project.repositories.mavenCentral().url
|
||||
//
|
||||
// patternLayout {
|
||||
//
|
||||
// // com/google/protobuf/protoc/3.9.2/protoc-3.9.2-linux-aarch_64.exe
|
||||
// artifact("[organisation]/[module]/[revision]/[artifact]-[revision]-${os.name}-${arch.name}.[ext]")
|
||||
//
|
||||
//// artifact("3rd-party-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]")
|
||||
//// artifact("company-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]")
|
||||
//// ivy("ivy-files/[organisation]/[module]/[revision]/ivy.xml")
|
||||
//// artifact("[organisation]/[module]/[revision]/[artifact]-[revision].[ext]")
|
||||
// setM2compatible(true)
|
||||
// metadataSources {
|
||||
// artifact()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
tasks.register<Sync>("protocExecCopy") {
|
||||
group = project.name
|
||||
|
||||
// from(protocConfiguration.artifacts)
|
||||
|
||||
from(protocConfiguration.resolve())
|
||||
|
||||
into(project.layout.buildDirectory.dir("protocCopy"))
|
||||
}
|
||||
|
||||
//tasks.register("dlPc") {
|
||||
// group = project.name
|
||||
//
|
||||
// val downloadDir = this.temporaryDir
|
||||
//
|
||||
// outputs.dir(downloadDir)
|
||||
//
|
||||
// doLast {
|
||||
//
|
||||
//// downloadDir.mkdirs()
|
||||
//
|
||||
// val protocArtifactFileExt = "exe"
|
||||
//
|
||||
// val osFamilyName = DefaultNativePlatform.host().operatingSystem.toFamilyName()
|
||||
//
|
||||
// val arch: String =
|
||||
// DefaultNativePlatform.getCurrentArchitecture()
|
||||
// .name
|
||||
// .replace("-", "_")
|
||||
//
|
||||
// val artifact = "protoc-$protocVersion-${osFamilyName}-${arch}.$protocArtifactFileExt"
|
||||
//
|
||||
// val uri = uri(
|
||||
// ArtifactRepositoryContainer.MAVEN_CENTRAL_URL
|
||||
// + "com/google/protobuf/protoc/$protocVersion/$artifact"
|
||||
// )
|
||||
// // actual:
|
||||
// // https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-windows-x86_64.exe
|
||||
// // https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-windows-x86-64.exe
|
||||
//
|
||||
// ant.invokeMethod(
|
||||
// "get", mapOf(
|
||||
// "src" to uri,
|
||||
// "dest" to downloadDir.canonicalPath,
|
||||
// "verbose" to true,
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
package dev.adamko.gradle.pbandg
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.ExternalDependency
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.domainObjectContainer
|
||||
import org.gradle.kotlin.dsl.create
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
||||
|
||||
|
||||
class ProtocPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
|
||||
val protocConfig =
|
||||
project.extensions.create("protocConfig", ProtocConfigExtension::class.java)
|
||||
|
||||
val protocDeps = project.configurations.create("pbAndG") {
|
||||
isVisible = false
|
||||
isCanBeConsumed = false
|
||||
isCanBeResolved = true
|
||||
description = "protoc dependencies"
|
||||
|
||||
defaultDependencies {
|
||||
// deps += project.dependencies.create("com.google.protobuf:protoc:3.19.0")
|
||||
add(protocConfig.dependencyProvider())
|
||||
}
|
||||
}
|
||||
|
||||
val generatorsContainer =
|
||||
project.objects.domainObjectContainer(ProtocGenerationTask::class.java)
|
||||
protocConfig.extensions.add("generate", generatorsContainer)
|
||||
|
||||
|
||||
project.extensions.add("asd", project.provider {
|
||||
DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName()
|
||||
})
|
||||
|
||||
project.tasks.withType<ProtocGenerationTask> {
|
||||
// .getDataFiles()?.from(protocDeps)
|
||||
}
|
||||
|
||||
// project.getPlugins().withType(org.gradle.api.plugins.JavaPlugin::class) { javaPlugin ->
|
||||
// val sourceSets: SourceSetContainer =
|
||||
// project.getExtensions().getByType(SourceSetContainer::class.java)
|
||||
// val main: SourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
|
||||
// main.getJava().setSrcDirs(Arrays.asList("src"))
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract class ProtocConfigExtension(private val project: Project) : ExtensionAware {
|
||||
|
||||
val protocVersion: Property<String> =
|
||||
project.objects.property(String::class).convention("3.9.2")
|
||||
|
||||
val protocGroup: Property<String> =
|
||||
project.objects.property(String::class).convention("com.google.protobuf")
|
||||
|
||||
val protocArtifactName: Property<String> =
|
||||
project.objects.property(String::class).convention("protoc")
|
||||
|
||||
val protocArtifactExtension: Property<String> =
|
||||
project.objects.property(String::class).convention("exe")
|
||||
|
||||
var osFamilyNameProvider: () -> String = {
|
||||
DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName()
|
||||
}
|
||||
|
||||
var architectureProviderMapper: (String) -> String = {
|
||||
it.replace("-", "_")
|
||||
}
|
||||
|
||||
var architectureProvider: () -> String = {
|
||||
DefaultNativePlatform.getCurrentArchitecture()
|
||||
.name
|
||||
.let(architectureProviderMapper)
|
||||
}
|
||||
|
||||
var classifierProvider: () -> String = {
|
||||
"${osFamilyNameProvider()}-${architectureProvider()}"
|
||||
}
|
||||
|
||||
var dependencyProvider: () -> ExternalDependency = {
|
||||
project.dependencies.create(
|
||||
group = protocGroup.get(),
|
||||
name = protocArtifactName.get(),
|
||||
version = protocVersion.get(),
|
||||
classifier = classifierProvider(),
|
||||
ext = protocArtifactExtension.get(),
|
||||
)
|
||||
}
|
||||
|
||||
val generators = project.objects.domainObjectContainer(ProtocGenerationConfig::class)
|
||||
|
||||
|
||||
}
|
||||
|
||||
abstract class ProtocGenerationConfig
|
||||
|
||||
abstract class ProtocGenerationTask : DefaultTask() {
|
||||
|
||||
@TaskAction
|
||||
fun generate() {
|
||||
logger.lifecycle("generating protoc...")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//class ProtocDownloadExe : DefaultTask() {
|
||||
//
|
||||
////@Input
|
||||
//val protocVersion = "3.9.2"
|
||||
//val protocArtifactFileExt = "exe"
|
||||
//
|
||||
//
|
||||
// @TaskAction
|
||||
// fun download() {
|
||||
//
|
||||
// val baseUri = project.repositories.mavenCentral().url
|
||||
//
|
||||
// val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
|
||||
// val arch: ArchitectureInternal = DefaultNativePlatform.getCurrentArchitecture()
|
||||
//
|
||||
// val artifact = "protoc-$protocVersion-${os.name}-${arch.name}.$protocArtifactFileExt"
|
||||
//
|
||||
// ant.invokeMethod(
|
||||
// "get", mapOf(
|
||||
// "src" to baseUri.resolve("/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-linux-aarch_64.exe"),
|
||||
// "dest" to project.layout.buildDirectory.dir("protoc-artifact"),
|
||||
// "verbose" to true,
|
||||
// )
|
||||
// )
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
Loading…
Add table
Add a link
Reference in a new issue