Bug 66191 - compile taglibs that are not (yet) included in jsp file
Summary: compile taglibs that are not (yet) included in jsp file
Status: NEW
Alias: None
Product: Tomcat 10
Classification: Unclassified
Component: Jasper (show other bugs)
Version: unspecified
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ------
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-01 10:02 UTC by andreas.stange
Modified: 2022-08-23 13:47 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description andreas.stange 2022-08-01 10:02:35 UTC
## Issue Description
We are using jetty-jspc-maven-plugin (which uses Jasper JspC) to compile jsp and tag files in our build.
We have some Maven projects that contain only taglibs (tld files) but no jsp files.

Sadly, these taglibs are not compiled when the project is compiled.

It seems the jsp compiler does a top to bottom approach, starting with jsp files and including everything in the compilation that is reachable from these.
Because our taglib project does not contain a jsp file, nothing is compiled.

When including tag files explicitly ( <includes>**/*.tag, **/*.jsp, **/*.jspx</includes> ) then these are still considered as jsp files and it results in an error: [&lt;%@ tag] directive can only be used in a tag file

## Desired Solution
Include an option compileUnusedTaglibs (name is only a suggestion).
It should search for tld files and compile everything that is reachable from these.

## Motivation
At the moment, our taglib is only compiled as part of a later project.
Sadly, project dependencies are not enforced because of this.

Example:
- TaglibProject is Referenced by WebAppProject.
- TaglibProject uses Java classes from WebAppProject prematurely in tag files
- TaglibProject tag files are not compiled yet. Thus no error.
- WebAppProject is compiled. The prematurely used Java files are not present. Thus no error.

It works. But it would be better for our project structure, if it would not be possible to use classes from later projects prematurely in tag files or earlier projects. taglib compilation would enforce this.

You can find here a small example project to reproduce the issue: https://github.com/achimmihca/multi.module.webapp.demo

## Additional Notes
I was redirected here from the jetty-jspc-maven-plugin team: https://github.com/eclipse/jetty.project/issues/8316
Comment 1 andreas.stange 2022-08-01 10:06:17 UTC
> The prematurely used Java files are not present. Thus no error.

Should be "The prematurely used Java files are NOW present. Thus no error."
Comment 2 Mark Thomas 2022-08-23 13:27:09 UTC
Moving this to an enhancement.

Given that the compilation of the tag files is simply a means to an ends (dependency management) I wonder if there is a simpler solution.
Comment 3 andreas.stange 2022-08-23 13:47:54 UTC
> Given that the compilation of the tag files is simply a means to an ends
> (dependency management) I wonder if there is a simpler solution.

We could write a test that scans our tag files to check that no import of a prematurely used class exists.

However, the JSP compiler has info what is on the classpath, transitive dependencies etc. Thus, I argue that compilation would be the better solution.

When not compiling tag files, errors will always be delayed to later projects. For example, unsupported Java language features (depends on language level configuration) or syntax errors. But yes, this is a minor issue because the error will show up eventually.