Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose org.graalvm.sdk:graal-sdk dependency as compileOnlyApi #352

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

jamesfredley
Copy link

This saves having to add it to every Grails 7 application

This saves having to add it to every Grails 7 application
@codeconsole
Copy link
Contributor

That dependency is not required. I am running a Grails 7 app and Asset Pipeline 5.0.1 and do not need it.

@davydotcom
Copy link
Contributor

This is only needed for compile time or development runtime. We wanted to explicitly exclude it from getting injected into the war/jar because its not required for production war builds.

@jamesfredley
Copy link
Author

Without this dependency added to the grails 7 test apps:

runtimeOnly("org.graalvm.sdk:graal-sdk:22.0.0.2")

the following has occurred across a number of test applications:

Grails application running at http://localhost:8080 in environment: development
2024-10-11T09:19:27.912-04:00 ERROR 7768 --- [io-8080-exec-10] .C.[.[.[.[dispatcherServletRegistration] : Servlet.service() for servlet [dispatcherServletRegistration] in context with path [] threw exception [Filter execution threw an exception] with root cause

java.lang.ClassNotFoundException: org.graalvm.polyglot.Context
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
	at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3427)
	at java.base/java.lang.Class.getMethods(Class.java:2019)
	at java.desktop/com.sun.beans.introspect.MethodInfo.get(MethodInfo.java:70)
	at java.desktop/com.sun.beans.introspect.ClassInfo.getMethods(ClassInfo.java:80)
	at java.desktop/java.beans.Introspector.getTargetMethodInfo(Introspector.java:1029)
	at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:446)
	at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:195)
	at groovy.lang.MetaClassImpl.lambda$addProperties$25(MetaClassImpl.java:3466)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at groovy.lang.MetaClassImpl.doPrivileged(MetaClassImpl.java:3519)
	at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3466)
	at groovy.lang.MetaClassImpl.reinitialize(MetaClassImpl.java:3448)
	at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3441)
	at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:272)
	at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:314)
	at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:269)
	at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:596)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:69)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:159)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:95)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
	at asset.pipeline.AbstractAssetFile.processedStream(AbstractAssetFile.groovy:180)
	at asset.pipeline.AbstractAssetFile.processedStream(AbstractAssetFile.groovy)
	at asset.pipeline.DirectiveProcessor.fileContents(DirectiveProcessor.groovy:320)
	at asset.pipeline.DirectiveProcessor$fileContents$2.call(Unknown Source)
	at asset.pipeline.AssetPipeline.serveUncompiledAsset(AssetPipeline.groovy:67)
	at asset.pipeline.AssetPipelineFilter.doFilterInternal(AssetPipelineFilter.groovy:288)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:113)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:384)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
	at java.base/java.lang.Thread.run(Thread.java:840)

@jamesfredley
Copy link
Author

jamesfredley commented Oct 11, 2024

@codeconsole's Grails 7 application doesn't need this dependency because he removed.

implementation("com.bertramlabs.plugins:asset-pipeline-gradle:5.0.4") from buildSrc/build.gradle, he actually fully consolidated buildSrc and settings.gradle into build.gradle, but that one line is the source of this error.

And has it defined in one location in build.gradle:

plugins {
     id "com.bertramlabs.asset-pipeline" version "5.0.4"
}

Example where it was required: https://github.com/jamesfredley/grails-website-test

We had planned to go that direction for forge create-app and grails-shell create-app, so if we don't think this will pop up in another way, we can close it.

@jamesfredley
Copy link
Author

grails/grails-forge#395

@davydotcom
Copy link
Contributor

so this issue is purely related to the gradle side?

@davydotcom
Copy link
Contributor

you do need it in grails run-app or dev but not in the final jar or war. need a way to inject this dependency but NOT package it in the war/jar

@mkobel
Copy link
Contributor

mkobel commented Nov 11, 2024

We have a similar, probably related, issue using spring boot .

A possible workaround is adding graalvm to implementation in build.gradle:

dependecies {
    [..]
    implementation 'org.graalvm.polyglot:js:24.1.1' // avoid java.lang.ClassNotFoundException: org.graalvm.polyglot.Value when calling js file
    implementation 'org.graalvm.polyglot:polyglot:24.1.1' // avoid java.lang.ClassNotFoundException: org.graalvm.polyglot.Value when 
calling js file
    [..]
}

Using implementation 'org.graalvm.sdk:graal-sdk:24.1.1' as workaround works too.

@fernando88to
Copy link

We have a similar, probably related, issue using spring boot .

A possible workaround is adding graalvm to implementation in build.gradle:

dependecies {
    [..]
    implementation 'org.graalvm.polyglot:js:24.1.1' // avoid java.lang.ClassNotFoundException: org.graalvm.polyglot.Value when calling js file
    implementation 'org.graalvm.polyglot:polyglot:24.1.1' // avoid java.lang.ClassNotFoundException: org.graalvm.polyglot.Value when 
calling js file
    [..]
}

Using implementation 'org.graalvm.sdk:graal-sdk:24.1.1' as workaround works too.

With jdk 17 this solution above worked, but in my case I am using jdk 11 which is not compatible.

org/graalvm/polyglot/Value has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

@jamesfredley
Copy link
Author

jamesfredley commented Dec 9, 2024

This will end up being a somewhat frequent occurrence for those upgrading to Grails 7, that had been loading asset-pipeline-gradle in buildSrc or buildscript{} vs the new way in plugins{} by id/version only.

remove com.bertramlabs.plugins:asset-pipeline-gradle from buildSrc/build.gradle or buildscript{} in build.gradle:

implementation "com.bertramlabs.plugins:asset-pipeline-gradle:5.0.4"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:5.0.4"

also remove it from settings.gradle, if present

then define in build.gradle only with id and version:

plugins {
     id "com.bertramlabs.asset-pipeline" version "5.0.4"
}

@jdaugherty
Copy link
Contributor

@davydotcom Do you have a suggestion on how to make this available only during development? I'm assuming this is a gradle plugin change for grails?

@jamesfredley jamesfredley changed the title Expose org.graalvm.sdk:graal-sdk dependency Expose org.graalvm.sdk:graal-sdk dependency as compileOnlyApi Dec 9, 2024
@jamesfredley
Copy link
Author

Updated PR to use compileOnlyApi Gradle configuration instead of api.

https://docs.gradle.org/current/userguide/java_library_plugin.html
image

@codeconsole
Copy link
Contributor

I am not sure if compileOnlyApi would fix your issue because it sounds like it is happening at development runtime.

I don't recommend any change if it is only for people who are loading the plugin incorrectly. if it works in a plugins {} block, then that should be the requirement.

@davydotcom davydotcom merged commit 39e6434 into bertramdev:5.0.x Dec 10, 2024
@av-m
Copy link

av-m commented Dec 11, 2024

I am not sure if compileOnlyApi would fix your issue because it sounds like it is happening at development runtime.

Correct, the issue only arises during development runtime with our Spring Boot applications. As expected, the change to compileOnlyApi had no effect.

To have this working again as before commit fce79e6, the following asset-pipeline-core build.gradle dependency configurations are needed:

implementation 'org.graalvm.sdk:graal-sdk:22.0.0.2'
implementation 'org.graalvm.js:js:22.0.0.2'

@jamesfredley
Copy link
Author

compileOnlyApi did not address the development runtime issue.

More details are captured on grails/grails-core#13913 including the workaround we used for a number of Grails projects and on start.grails.org for Grails 6.2.2 and 7.0.0-SNAPSHOT.

grails/grails-core#13913 (comment) includes more details on the root issue, although all details of the root cause have not been tracked down.

@codeconsole
Copy link
Contributor

@av-m @jamesfredley is this a windows only or a jdk 17 issue? why do I not get this exception in development mode without these dependencies with jdk 21 on osx?

@fernando88to
Copy link

It also happens with JDK 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants