codeconsole opened a new pull request, #16356:
URL: https://github.com/apache/grails-core/pull/16356

   ## Summary
   
   `grails-converters` declares `jakarta.servlet:jakarta.servlet-api` as 
`compileOnly`, but it ships a Groovy extension module 
(`org.grails.web.converters.ConvertersExtension`, registered in 
`META-INF/services/org.codehaus.groovy.runtime.ExtensionModule`) whose 
`getJSON` and `getXML` signatures take `HttpServletRequest`. The Groovy 
compiler loads every extension module it finds on a compile classpath before 
compiling anything, and fails hard when one of its classes cannot load. So a 
module that depends on `grails-converters` without a web starter on its compile 
classpath, such as a plugin or a library, fails `compileGroovy`:
   
   ```
   General error during canonicalization: java.lang.NoClassDefFoundError:
   Unable to configure org.grails.web.converters.ConvertersExtension due to 
missing dependency jakarta/servlet/http/HttpServletRequest
   ```
   
   This change declares the servlet API `compileOnlyApi` instead, which is what 
`grails-controllers`, `grails-web-gsp` and `grails-web-taglib` already do for 
the same reason. Consumers get it on their compile classpath; the runtime 
classpath is still left to the container, so nothing is added next to 
`tomcat-embed-core`. The duplicate `compileOnly` line further down the same 
block is removed.
   
   ## Why it went unnoticed
   
   In an application the Boot web starter supplies the servlet API anyway. In a 
plugin build the CLI companion probe usually adds `grails-console` to the 
compile classpath, and `grails-console` drags `jakarta.servlet-api` in. A 
plugin built with `grailsCliAutoProvision=false` has neither and hits the error 
on its first `compileGroovy`.
   
   ## Verification
   
   - `:grails-converters:compileGroovy`, `generatePomFileForMavenPublication` 
and `generateMetadataFileForMavenPublication` pass.
   - Gradle module metadata carries `jakarta.servlet:jakarta.servlet-api` on 
`apiElements` only; `runtimeElements` is unchanged.
   - Reproduced the failure and the fix against a plugin module that declares 
only `grails-core` and `grails-converters`.
   
   ## Note on #16237
   
   That PR moves `getXML(HttpServletRequest)` into a new `grails-xml` module 
with its own extension module and the same `compileOnly` declaration, which 
reproduces this problem for `grails-xml` consumers. `compileOnlyApi` there too 
would keep both modules consistent.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to