I wrote a very simple groovy script to test if a cron expression is valid:
import hudson.scheduler.CronTabList
try {
def cron = CronTabList.create("@daily")
println("Valid cron!")
} catch(Exception e) {
println("Invalid cron!")
e.printStackTrace()
}
Running this fails with the message:
Caught: java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
at hudson.scheduler.BaseParser.<clinit>(BaseParser.java:149)
at hudson.scheduler.CronTab.set(CronTab.java:113)
at hudson.scheduler.CronTab.<init>(CronTab.java:100)
at hudson.scheduler.CronTabList.create(CronTabList.java:121)
at hudson.scheduler.CronTabList.create(CronTabList.java:96)
at hudson.scheduler.CronTabList$create.call(Unknown Source)
at validate_crontab.run(validate_crontab.groovy:7)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
... 7 more
Process finished with exit code 1
My build.gradle dependencies look like:
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.0'
compile group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.85'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
I simply can't figure out what's to blame and why I can't run the script.
Any help is much appreciated!