Gradle plugin Jasper jspc to precompile jsps

1.4k Views Asked by At

I'm using the jassper jspc gradle plugin I want to pre-compile all my jsps "on build", the configuration is as notice the documentation:

    buildscript {

        repositories {
            [...]
            maven {
                url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
            }
        }

        dependencies {
            [...]
"com.liferay.gradle.plugins.jasper.jspc", version: "2.0.1"
        }
    }
    [...]
    apply plugin: "com.liferay.jasper.jspc"

When I execute "gradle task" I can see the plugin tasks were created:

Verification tasks
------------------
check - Runs all checks.
compileJSP - Compile JSP files to check for errors.
test - Runs the unit tests.

But if I luch one of the tasks, for example gradle compileJSP I get the same error:

:project-web:generateJSPJava
Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.liferay.jasper.jspc.JspC.main(JspC.java:52)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.liferay.jasper.jspc.JspC._runWithClassPath(JspC.java:168)
        at com.liferay.jasper.jspc.JspC.main(JspC.java:46)
Caused by: java.lang.NoSuchMethodError: javax.el.ExpressionFactory.newInstance()Ljavax/el/ExpressionFactory;
        at org.apache.jasper.compiler.JspUtil.getExpressionFactory(JspUtil.java:1192)
        at org.apache.jasper.compiler.JspUtil.validateExpressions(JspUtil.java:654)
        at org.apache.jasper.compiler.Validator$ValidateVisitor.getJspAttribute(Validator.java:1366)
        at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1142)
        at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:859)
        at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1502)
        at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2297)
        at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2347)
        at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2353)
        at org.apache.jasper.compiler.Node$Root.accept(Node.java:499)
        at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2297)
        at org.apache.jasper.compiler.Validator.validate(Validator.java:1890)
        at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:223)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
        at org.apache.jasper.JspC.processFile(JspC.java:1178)
        at org.apache.jasper.JspC.execute(JspC.java:1345)
        ... 6 more
:project-web:generateJSPJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':project-web:generateJSPJava'.
> Process 'command '/home/[...]/.sdkman/candidates/java/8u121/bin/java'' finished with non-zero exit value 1

Any idea or alternative solution?

2

There are 2 best solutions below

0
user2992476 On BEST ANSWER

Definitively this plugin is not working anymore. In addition nobody is using it (check maven repo use)

5
lance-java On

It seems that the version of javax.el.ExpressionFactory you are using at runtime is different to the version of javax.el.ExpressionFactory that the jasper.jspc plugin was compiled against.

I've done a jar search here on maven central for javax.el.ExpressionFactory. Perhaps you could use gradle dependencyInsight to see why the class version has changed.

If you want to see where the class is located you could add this to your build.

task printExpressionFactoryLocations {
    doLast {
        String findMe = 'javax/el/ExpressionFactory.class'
        def configuration = buildscript.configurations.classpath
        def jars = configuration.asFileTree.matching {
            include '*.jar'
        }
        jars.files.each { File jar ->
            def entries = zipTree(jar).matching {
               include findMe
            }
            if (!entries.files.empty) {
               println "Found $findMe in $jar.name"
            }
        }
    }
}