Gradle 插件Jasper jspc预编译jsps

Gradle plugin Jasper jspc to precompile jsps

我正在使用 jassper jspc gradle plugin 我想预编译我所有的 jsps "on build",配置如文档所述:

    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"

当我执行 "gradle task" 时,我可以看到创建了插件任务:

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

但是如果我完成其中一项任务,例如 gradle compileJSP,我会得到同样的错误:

: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

任何想法或替代解决方案?

您在运行时使用的 javax.el.ExpressionFactory 版本似乎与编译 jasper.jspc 插件所针对的 javax.el.ExpressionFactory 版本不同。

我在 Maven Central 上为 javax.el.ExpressionFactory 进行了 jar 搜索 here。或许您可以使用 gradle dependencyInsight 查看 class 版本发生变化的原因。

如果您想查看 class 的位置,您可以将其添加到您的构建中。

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"
            }
        }
    }
}

这个插件肯定不能用了。另外没有人在使用它(检查 maven repo use)