Hello.
I’m trying to migrate an Ant build (which gave me some gray hair already) to Gradle (I was told it’s better). My problem with it is that I managed to run it once, but it won’t do it any more. I’ve tried deleting .gradle directory, modifying the files specified as inputs, installing different versions (1.0, 1.8, 1.9 and 2.0). 1.0 - I was never able to compile anything, same for 2.0 - some internal build errors unrelated to my project, 1.8 and 1.9 behave the same. Below is the relevant script:
task previewFonts {
inputs.dir "./fonts"
inputs.file "./templates/Preview.as.template"
outputs.dir "./ant/previews"
}
previewFonts << {
def generatedAs = "./generated/previews"
FileTree tree = fileTree(dir: "./fonts")
tree.include "**/regular/*.otf"
tree.include "**/regular/*.ttf"
file("./ant/previews").mkdirs()
file(generatedAs).mkdirs()
tree.each { f ->
def d = f.getParentFile()
d = d.getParentFile()
def fname = f.getName().replaceFirst("[.][^.]+\$", "")
def plocation = d.getPath() + "/description.properties"
Properties props = new Properties();
props.load(new FileInputStream(plocation))
def pname = new String(
props.getProperty("preview.name").getBytes("ISO-8859-1"), "UTF-8");
def png = "./ant/previews/${pname}.png"
def converter = task "convert${d.getName()}${fname}" {
inputs.file f
inputs.file plocation
println "convert task declared"
}
converter << {
println "recompiling"
def label = "label:" + new String(
props.getProperty("preview.text").getBytes("ISO-8859-1"), "UTF-8");
def fg = "label:" + props.getProperty("preview.foreground")
def bg = props.getProperty("preview.background")
def size = props.getProperty("preview.size")
new ByteArrayOutputStream().withStream { es ->
def result = exec {
errorOutput = es
executable = "convert"
args "-background", bg, "-fill", fg, "-pointsize", size,
"-font", f, label, png
}
// TODO: Find out how to get the error message.
if (result.getExitValue() != 0) {
def message = new String("Preview not created: ${es.toString()}")
throw new GradleScriptException(message,
new RuntimeException(message));
}
}
}
def copier = tasks.create(name: "asTemplate${d.getName()}${fname}", type: Copy) {
def aname = pascalCase fname
println "rebuilding template ${generatedAs}/${aname}"
from "./templates"
into "${generatedAs}"
include "Preview.as.template"
}
copier.doLast {
println "doLast ${aname}"
rename { file -> println("renaming: ${file} to ${aname}"); "${aname}.as" }
expand(asClass: "${aname}", png: png)
}
}
}
Here’s example output I get for running ./gradlew -i previewFonts -C rebuild
Please use CMSClassUnloadingEnabled in place of CMSPermGenSweepingEnabled in the future
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file '/home/wvxvw/workspace/fonts/build.gradle'.
Included projects: [root project 'fonts']
Evaluating root project 'fonts' using build file '/home/wvxvw/workspace/fonts/build.gradle'.
Compiling build file '/home/wvxvw/workspace/fonts/build.gradle' using BuildScriptClasspathScriptTransformer.
Compiling build file '/home/wvxvw/workspace/fonts/build.gradle' using BuildScriptTransformer.
All projects evaluated.
Selected primary task 'previewFonts'
Tasks to be executed: [task ':previewFonts']
:previewFonts (Thread[main,5,main]) started.
:previewFonts
Executing task ':previewFonts' (up-to-date check took 0.613 secs) due to:
No history is available.
convert task declared
rebuilding template ./generated/previews/ChampagneLimousines
convert task declared
... (lots more of the same)
convert task declared
rebuilding template ./generated/previews/UNIVERSALFRUITCAKE
:previewFonts (Thread[main,5,main]) completed. Took 1.038 secs.
BUILD SUCCESSFUL
Total time: 4.413 secs
This, obviously, didn’t do anything, i.e. no previews were generated. (4.5 seconds for doing absolutely nothing seems like a farily long time though…) Anyways, how do I handle this situation? Where to look? Any logs with explanations for why the task wasn’t executed? I’ve searched StackOverflow and the documentation for forcing task execution, but all I could find is that “it’s not supported”…