java - Versioning Gradle native plugin builds -
here's first attempt @ c program built gradle's c plugin:
apply plugin: 'c' model { components { derpus(nativeexecutablespec) { sources { c(csourceset) { source { srcdir "src/derpus/c" include "**/*.c" } exportedheaders { srcdir "src/derpus/headers" } } } } } } this produces executable called derpus.exe. like, if @ possible, version these executables (derpus-1.0.0.exe, derpus-1.0.1.exe, etc.). when change derpus closure derpus-1.0.0 so:
derpus-1.0.0(nativeexecutablespec) {
and run gradle clean build get:
d:\workspace\derp\20150505\derpus>gradlew clean build failure: build failed exception. * where: build file 'd:\derpus\build.gradle' line: 6 * went wrong: not compile build file 'd:\derpus\build.gradle'. > startup failed: build file 'd:\derpus\build.gradle': 6: unexpected tok en: 0 @ line 6, column 20. derpus-1.0.0(nativeexecutablespec) { ^ 1 error does know of way version these executables?
update
now really weird! taking amnon's advice, added gradle.properties file defined version=1.0.0. modified model closure to:
model { components { derpus(nativeexecutablespec) { sources { c(csourceset) { source { srcdir "src/derpus/c" include "**/*.c" } exportedheaders { srcdir "src/derpus/headers" } } } basename = "derpus-${version}" } } } this produces executable named derpus-1 (what?!?!)!
so modified model again:
version = "3.4" model { components { derpus(nativeexecutablespec) { sources { c(csourceset) { source { srcdir "src/derpus/c" include "**/*.c" } exportedheaders { srcdir "src/derpus/headers" } } } basename = "derpus-${version}" } } } as can see, should overrdide version set in gradle.properties, after running gradle clean build, produces derpus-3!
so modified model yet again:
model { components { derpus(nativeexecutablespec) { sources { c(csourceset) { source { srcdir "src/derpus/c" include "**/*.c" } exportedheaders { srcdir "src/derpus/headers" } } } basename = "derpus-3.4.5" } } } this produces derpus-3.4!!! what going on here?!? c plugin have bug in doesn't honor full version variable?
in example above problem derpus-1.0.0 gradle things dash character minus unexpected in component spec name, failure. can overcome wrapping derpus-1.0.0 inverted commas. better approach, however, apply version basename property of component spec, i.e. add following line under derpus component definition:
basename = "derpus-1.0.0" or
basename = "derpus-$version" where in second case version property $version taken project object.
update
per smeeb comments below workaround can applied directly rename target binaries:
afterevaluate { renamenativebinaries() } def renamenativebinaries() { binaries.all { b -> if (b instanceof sharedlibrarybinaryspec) { b.sharedlibraryfile = reconstructfilename(b.sharedlibraryfile) } else if (b instanceof staticlibrarybinaryspec) { b.staticlibraryfile = reconstructfilename(b.staticlibraryfile) } } } def reconstructfilename(file originalfile) { def originalfilename = originalfile.absolutepath def filepath = filenameutils.getfullpath(originalfilename) def basename = filenameutils.getbasename(originalfilename) def extension = filenameutils.getextension(originalfilename) def newname = "$basename-$version.$extension" def newfile = new file(filepath, newname) newfile } where filenameutils taken commons-io:
buildscript { repositories { mavencentral() } dependencies { classpath group: 'commons-io', name: 'commons-io', version: '2.4' } }
Comments
Post a Comment