Skip to content

Commit

Permalink
[#29] read the version from processed resources
Browse files Browse the repository at this point in the history
this way the version is actually the version from the plugin's project
and not the version of the project to which the plugin is being applied
  • Loading branch information
kdabir committed Aug 9, 2020
1 parent 3b78835 commit ab816d1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ plugins {

subprojects {
group = 'com.medly.apifi'

repositories {
jcenter()
}
}

configure(subprojects.findAll {it.name != 'plugin'}) {
configure(subprojects.findAll {it.name != 'plugin'}) { // no java component publishing for plugin
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.kapt'
apply plugin: "com.kdabir.mksrc"
apply plugin: "maven-publish"


repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom')
Expand Down Expand Up @@ -82,14 +80,16 @@ project(":cli") {
project(":runtime") {

dependencies {
kapt(platform("io.micronaut:micronaut-bom:$micronautVersion"))
kapt("io.micronaut:micronaut-inject-java")
// todo do we need kapt in this project?
// kapt(platform("io.micronaut:micronaut-bom:$micronautVersion"))
// kapt("io.micronaut:micronaut-inject-java")

implementation(platform("io.micronaut:micronaut-bom:$micronautVersion"))
implementation("io.micronaut:micronaut-inject")
implementation("io.micronaut:micronaut-http")
implementation("io.micronaut:micronaut-http-server")

kaptTest("io.micronaut:micronaut-inject-java")
// todo do we need kapt in this project?
// kaptTest("io.micronaut:micronaut-inject-java")
}
}
10 changes: 10 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ plugins {
dependencies {
implementation project(":codegen")
}

project.afterEvaluate {
tasks.withType(ProcessResources) { processResources ->
inputs.property('projectVersion', project.version)

filesMatching("version.properties") {
expand('projectVersion': project.version)
}
}
}
2 changes: 2 additions & 0 deletions plugin/src/main/groovy/apifi/ApifiCodegen.groovy
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package apifi

import apifi.codegen.*
import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

@CompileStatic
class ApifiCodegen extends DefaultTask {

@InputFile
Expand Down
22 changes: 22 additions & 0 deletions plugin/src/main/groovy/apifi/VersionLoader.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package apifi

import groovy.transform.CompileStatic

@CompileStatic
class VersionLoader {
static final String VERSION_PROPERTIES_PATH = "/version.properties"

private static String load() {
def stream = VersionLoader.getResourceAsStream(VERSION_PROPERTIES_PATH)
if (stream == null) {
throw new RuntimeException("""\
Could not load version.properties.
This could happen when plugin jar is deleted
Try Stopping Gradle Daemon (gradle --stop)""".stripIndent())
}
final Properties versions = new Properties()
versions.load(stream);

return versions['project.version'] ?: 'unspecified'
}
}
4 changes: 3 additions & 1 deletion plugin/src/main/groovy/com.medly.apifi.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
def apifiVersion = apifi.VersionLoader.load()

dependencies {
implementation(group: 'com.medly.apifi', name: 'runtime', version: this.getVersion())
implementation(group: 'com.medly.apifi', name: 'runtime', version: apifiVersion)
}

tasks.register('apifi', apifi.ApifiCodegen)
1 change: 1 addition & 0 deletions plugin/src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.version=${projectVersion}

0 comments on commit ab816d1

Please sign in to comment.