My question regards the sequencing of actions within tasks. I am using Gradle 2.4.
I have three tasks:
– execute is type:JavaExec and runs a Xalan XSLT transform. It writes errors to FileOutputStream(‘docout.err’)
– copyImagesCss is type:Copy and copies a directory and other files to a destination directory (where they are referenced by HTML files created by execute)
– cleanup is type:Delete and deletes the results of the last run, including docout.err
To order these tasks I use
copyImagesCss.dependsOn cleanup
execute.dependsOn copyImagesCss
So I expect that all old files will be deleted, that other files will be copied, and the transform will execute. This is what happens. When the run this, I see
$ gradle execute
:cleanup
:copyImagesCss
:execute
<?xml version="1.0" encoding="UTF-8"?>
BUILD SUCCESSFUL
Total time: 7.01 secs
The problem–although execute is the last task run and should create docout.err, docout.err is not present. It is as if the delete of docout.err in cleanup is happening after execute runs. Nothing else created by copyImagesCss or execute are deleted. Why? This is not so important here, but I’m wondering about future builds that I may plan.
You need to show us your tasks and maybe gradle --info or --debug traces, because it should work as you expect
My build.gradle looks like.
apply plugin: 'application'
repositories {
mavenLocal()
mavenCentral()
}
configurations {
xalan
}
dependencies {
xalan 'xalan:xalan:2.7.2'
}
task execute(type:JavaExec) {
description 'Builds manual.'
classpath configurations.xalan
errorOutput = new FileOutputStream('docout.err')
main = 'org.apache.xalan.xslt.Process'
args = [
'-IN', './manual/desktopmanual.xml',
'-XSL', 'http://docbook.sourceforge.net/release/xsl/1.78.1/xhtml5/chunk.xsl',
'-param', 'base.dir', 'desktopout',
'-param', 'html.stylesheet', 'stylesheet.css',
'-param', 'html.ext', '.html',
'-param', 'admon.graphics', '1',
'-param', 'navig.graphics', '1',
'-param', 'navig.graphics.extension', '.png',
'-param', 'ignore.image.scaling', '1'
].toList()
}
task cleanup(type:Delete) {
description 'Cleans out last manual build.'
delete 'manual/desktopout'
delete 'docout.err'
}
task copyImagesCss(type:Copy) {
description 'Adds images and CSS to manual build.'
from ('./manual') {
include 'images/**'
include 'dtscrn/**'
include 'stylesheet.css'
}
into './manual/desktopout'
}
copyImagesCss.dependsOn cleanup
execute.dependsOn copyImagesCss
I see no reference to docout.err when I run gradle --info execute
. When I run gradle --debug execute
I see one reference:
15:06:32.421 [DEBUG] [org.gradle.api.internal.file.copy.DeleteActionImpl] Deleting /Users/thad/experimental/db/docout.err
Just to be sure, if you execute
'java -jar /path/to/xalan/jar -IN ./manual/desktopmanual.xml ... all your args here'
Does it work ?
What’s the generated outputs and where are they located ?
My build.gradle works fine except for the missing docout.err file. And if I comment out delete 'docout.err'
, docout.err is present on completion and is rewritten with each subsequent call of gradle execute
.
Process performs an XSLT transform on ./manual/desktopmanual.xml using the chunk.xsl stylesheet. The other settings are flags for the DocBook 5 XSL. The result is a set of HTML files in ./manual/desktopout. This is the webapp’s user’s manual, which is distributed in the same WAR file. At different places the user clicks a help icon to open a context sensitive help page. The docout.err file lists the files the transform generates and any errors it encounters.
This transform also works from the command line, and from an Ant build.xml. However for newer applications we are moving from Ant to Gradle. Eventually these tasks and a copy task will be moved into the webapp’s build.gradle so as to compile and package the webapp in one command.
As I said, this is not a big deal for the current situation. I’m more concerned with what errors it might indicate for future, more complex builds.
I think I get it.
During your build ‘configuration phase’, your JaveExec task is configured, assigning a file output stream to docout.err
During your build ‘execution phase’ the docout.err file is removed, and this breaks the file output stream.
You need to assign the file output stream after execution of the delete task, for instance, in a doFirst{} block in your Javaexec task
Yes, that worked. I have now added
doFirst {
errorOutput = new FileOutputStream('docout.err')
}
to the execute task. Thanks.