java - Gradle + rhino execute scripts -
it second gradle using and, have little question of how execute js scripts in gradle.
i tried commandline , works fine
task optimizescript(type: exec) { commandline 'java', '-classpath', 'path/to/rhino/js.jar:path/to/closure/compiler.jar', 'org.mozilla.javascript.tools.shell.main', 'r.js', 'main.js' }
but think there better way of using gradle. maybe can execute script without commandline? think first can dependencies mvn, , next write script like
dependencies { compile rhino compile otherstuff } task optimizescript() { org.mozilla.javascript.tools.shell.main('r.js main.js') }
(of course script doesn't work)
it can done in following way:
build.gradle
apply plugin: 'java' repositories { mavencentral() } dependencies { compile 'rhino:js:1.7r2' } task runjs(type: javaexec) { classpath configurations.compile main 'org.mozilla.javascript.tools.shell.main' args 'run.js' standardoutput = new fileoutputstream(project.file('stdout')) erroroutput = new fileoutputstream(project.file('stderr')) }
run.js
function f(x) { return x+1 } print(f(7))
after running gradle runjs
, stdout
file contains 8.
Comments
Post a Comment