From e39cfe7d73cd2dce4d10429bac6bd8225734b614 Mon Sep 17 00:00:00 2001 From: Marco Ferrer <35935108+marcoferrer@users.noreply.github.com> Date: Mon, 3 Feb 2020 23:19:47 -0500 Subject: [PATCH] Add artifact version resolution support to gradle plugin (#107) * add artifact version resolution via gradle plugin * update version and add note to example project --- CHANGELOG.md | 3 +++ example-project/build.gradle | 6 ++++-- kroto-plus-gradle-plugin/build.gradle | 10 ++++++++-- .../krotoplus/gradle/KrotoPlusGradlePlugin.kt | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17821c4..ecb8492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ _2020-02-03_ #### Proto Builders (DSL) * Fix: Dsl marker interfaces are properly omitted from generated code when disabled [PR-106](https://github.com/marcoferrer/kroto-plus/pull/106) +#### Gradle Plugin +* New: Automatically configure artifact version for project kroto dependencies with missing version [PR-107](https://github.com/marcoferrer/kroto-plus/pull/107) Thanks to @Fleshgrinder + ## Version 0.6.0 _2019-12-26_ * New: Update to Kotlin `1.3.61` [PR-97](https://github.com/marcoferrer/kroto-plus/pull/97) diff --git a/example-project/build.gradle b/example-project/build.gradle index 72a0b0b..cdc4e5a 100644 --- a/example-project/build.gradle +++ b/example-project/build.gradle @@ -24,7 +24,7 @@ plugins { id 'idea' 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" + id "com.github.marcoferrer.kroto-plus" version "0.6.1" } group = 'com.github.marcoferrer.krotoplus' @@ -62,10 +62,12 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutines}" implementation "com.google.protobuf:protobuf-java:${versions.protobuf}" - implementation "com.github.marcoferrer.krotoplus:kroto-plus-coroutines:${versions.krotoplus}" implementation "com.github.marcoferrer.krotoplus:kroto-plus-test:${versions.krotoplus}" implementation "com.github.marcoferrer.krotoplus:kroto-plus-message:${versions.krotoplus}" + // Alternatively you can omit the artifact version if the Kroto+ gradle plugin is applied. + implementation "com.github.marcoferrer.krotoplus:kroto-plus-coroutines" + implementation "io.grpc:grpc-protobuf:${versions.grpc}", "io.grpc:grpc-stub:${versions.grpc}", "io.grpc:grpc-netty:${versions.grpc}" diff --git a/kroto-plus-gradle-plugin/build.gradle b/kroto-plus-gradle-plugin/build.gradle index 29ccb5f..814a467 100644 --- a/kroto-plus-gradle-plugin/build.gradle +++ b/kroto-plus-gradle-plugin/build.gradle @@ -64,10 +64,16 @@ protobuf { generateProtoTasks { def krotoConfig = file("krotoPlusConfig.asciipb") - all().each{ task -> + all().each { task -> task.dependsOn ':kroto-plus-gradle-plugin:gen-config-dsl:jar' configProtoTaskWithKroto(task, krotoConfig) } } -} \ No newline at end of file +} + +tasks.withType(Jar).each { task -> + task.manifest { + attributes 'Implementation-Version': project.version + } +} diff --git a/kroto-plus-gradle-plugin/src/main/kotlin/com/github/marcoferrer/krotoplus/gradle/KrotoPlusGradlePlugin.kt b/kroto-plus-gradle-plugin/src/main/kotlin/com/github/marcoferrer/krotoplus/gradle/KrotoPlusGradlePlugin.kt index dc84cc1..7961797 100644 --- a/kroto-plus-gradle-plugin/src/main/kotlin/com/github/marcoferrer/krotoplus/gradle/KrotoPlusGradlePlugin.kt +++ b/kroto-plus-gradle-plugin/src/main/kotlin/com/github/marcoferrer/krotoplus/gradle/KrotoPlusGradlePlugin.kt @@ -39,9 +39,23 @@ class KrotoPlusGradlePlugin : Plugin { } } } + + project.configurations.all { config -> + config.resolutionStrategy.eachDependency { details -> + if(details.requested.group == "com.github.marcoferrer.krotoplus" && + details.requested.version.isNullOrBlank()) { + + details.useVersion(Manifest.implVersion) + } + } + } } companion object { private const val PROTOBUF_PLUGIN_ID = "com.google.protobuf" } } + +object Manifest { + val implVersion = this::class.java.`package`.implementationVersion.orEmpty() +} \ No newline at end of file