Gradle daemon holds lock on jar file in build folder


(Greg) #1

The Jetty Jasper compiler only examines manifests of JARs in the WEB-INF folder rather than those on the classpath. For that reason, my gradle (2.12) script copies the jstl jar file from the jasper classpath to the build folder to enable the Jasper compiler to do it’s business.

This works fine the first time; however on subsequent runs the “clean” task fails - because the gradle daemon still has this file locked. Is there any way to force the daemon to drop this lock, or am I simply unable to use the daemon for this script on Windows? (My suspicion is that it will be fine on Linux where locking is less of an issue)

I’ve narrowed down the problem to the attached script, with the following output:
C:\Greg\jsptest>gradle -q --stop
C:\Greg\jsptest>gradle -q clean compileJsp
C:\Greg\jsptest>gradle -q clean compileJsp
`FAILURE: Build failed with an exception.`
* What went wrong:
Execution failed for task ':clean'.
> Unable to delete file: C:\Greg\jsptest\build\jsp\WEB-INF\lib\jstl-1.2.jar
`* Try:` `Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.`
C:\Greg\jsptest>

My script is as follows; perhaps I’m missing something, any ideas?

apply plugin: ‘war’

def jspSource = "$projectDir/src/main/webapp"
def jspTarget = “$buildDir/jsp”

repositories {
mavenCentral()
}

configurations {
jasper
}

dependencies {
jasper 'org.mortbay.jasper:apache-jsp:8.0.9.M3’
jasper 'javax.servlet:javax.servlet-api:3.1.0’
jasper ‘javax.servlet:jstl:1.2’
}

task copyJsp(type: Copy) {
from "$jspSource"
into “$jspTarget”
}

task copyJstl(type: Copy) {
from configurations.jasper
include 'jstl.jar’
into “$jspTarget/WEB-INF/lib/”
}

task compileJsp(dependsOn: [‘copyJsp’, ‘copyJstl’]) << {
ant.taskdef(classname: ‘org.apache.jasper.JspC’, name: ‘jasper’, classpath: configurations.jasper.asPath)
ant.jasper(package: “com.example.jsp”, uriRoot: “$jspTarget”, outputDir: “$jspTarget”, addWebXmlMappings: true, webXmlFragment: “$jspTarget/web.xml_fragment”)
}