Disable reloading in Grails 3.1 / springloaded - grails

I'm trying to disable automatic reload/recompiling in Grails 3.1 as I would like to use JRebel instead.
I find springloaded rather limited, but more importantly is constantly fails with
File /Users/engrun/Development/projects/grailsPoc/grails-app/controllers/grailsPoc/HelloController.groovy changed, recompiling...
java.lang.IllegalAccessException: Class org.springsource.loaded.ReloadableType can not access a member of class org.springframework.aop.framework.CglibAopProxy$ClassLoaderAwareUndeclaredThrowableStrategy with modifiers "public"
I have tried all kinds of settings that I have found available, however, none actually disables reloading when running the run-app command
I have tried
disable.auto.recompile=true
on command line, GRAILS_OPTS, and in application.yml
I have tried the
-noreloading
flag, both on command line and GRAILS_OPTS.
According to docs, this should have worked
https://grails.org/wiki/Auto%20Reloading
And the answer accepted as the correct one here
how can I disable reloading in a grails 3.0.0 app?
does not work either.
Have anyone actually succeeded in disabling auto-reloading in Grails 3.1?
(And successfully configured Grails 3 with JRebel?)

In 3.x apps you can disable Spring Loaded by adding
grails {
agent {
enabled = false
}
}
to build.gradle.

Burt's answer is correct related to the question -> how to disable autoreloading.
However, Anton's answer is relevant to the second/related issue on getting Jrebel to work.
I now have a working example, which works with both
gradle bootRun -Pjrebel -> disable springloaded, using jrebel
gradle bootRun -> uses springloaded
and
grails
grails> run-app
My config is a combination of
export GRAILS_OPTS="-javaagent:$JREBEL_HOME/jrebel.jar -Drebel.base=/Users/<username>/.jrebel"
and build.gradle
rebel {
alwaysGenerate = false
showGenerated = true
//rebelXmlDirectory = "build/classes"
}
if (project.hasProperty('jrebel')) {
bootRun.dependsOn(generateRebel)
grails {
agent {
enabled = false
}
}
tasks.withType(JavaExec) {
jvmArgs "-javaagent:jrebel.jar"
jvmArgs "-Xverify:none"
}
}
Thanks #burt-beckwith and #anton-arhipov for your input!

To enable JRebel for Grails 3 project you need to configure -javaagent argument with the corresponding path the jrebel.jar in build.gradle file:
tasks.withType(JavaExec) { jvmArgs "-javaagent:jrebel.jar" }

Related

Grails 3.3.8 does not reload the changes made to the project

I have a project with grails 3.3.8, the problem is that once I edit a controller or a gsp file, the changes are not reflected in the web browser even though the following message appears when it detects a change:
Controller.groovy change, compiling...
I have tried to start the app in the following way:
grails -reloading run-app.
And also with:
// File: build.gradle
import grails.util.Environment
...
bootRun {
final Boolean reloadEnabled =
Boolean.valueOf(
System.properties[Environment.RELOAD_ENABLED])
if (reloadEnabled) {
systemProperty Environment.RELOAD_ENABLED, reloadEnabled
}
}
...
grails -Dgrails.env=custom -Dgrails.reload.enabled=true run-app
According to this link https://intellij-support.jetbrains.com/hc/en-us/community/posts/207602705-Grails-3-not-automatically-hot-swapping-changed-code-after-upgrading-to-2016-1-3 it appears that hot reloading of classes only suns to happen in grails 3.3.x when the environment is set to development.
I've not been able to confirm that for myself however. I notice you are providing "custom" as your environment. Maybe try changing it to the development environment and see if that helps.
Also just want to confirm that your not just seeing behaviour listed in Grails auto recompile never completes (Grails 3.3.6)

How to configure settings.groovy in order to use several repositories?

I just installed Grails 3.3.0 and I'd like to configure some custom repositories in the ${HOME}/user/.grails/settings.groovy file.
This is what I've done so far (Real URLs have been replaced for <someUrl1|2>):
grails {
profiles {
repositories {
repo1 {
url = "<someUrl1>"
snapshotsEnabled = true
}
repo2 {
url = "<someUrl2>"
snapshotsEnabled = true
}
}
}
}
Now, when I execute grails command on bash (Ubutu 16.04) it always tries to resolve the dependencies from the first repository (<someUrl1>)
Java: jdk8u141
Should this configuration be done like I did?
If not, How could I configure this file in order to use more than one repo for grails?
If having connectivity issues (or whatsoever), the first attempt to connect to the first repository fails, Does Grails tray to access the other ones declared?
Should this configuration be done like I did?
Yes, according to the documentation
Does Grails tray to access the other ones declared?
Yes, the list of repositories are passed into the constructor of this class.
https://github.com/grails/grails-core/blob/master/grails-shell/src/main/groovy/org/grails/cli/profile/repository/MavenProfileRepository.groovy#L48

Possible to Disable redis-cache plugin via config or otherwise?

I've been testing out the cache and redis-cache plugins and there is a way to disable the cache plugin with:
grails.cache.enabled=false
Unfortunately, there doesn't seem to be able to do the same for the redis-cache plugin. So when I disabled cache, the redis-cache plugin complains about a missing bean. Seems legit, but I'd really like to be able to disable all caching for local development. Suggestions?
As of now, the killswitch in the plugin is just not implemented. See code
One option here is to disable via BuildConfig. E.g. something like:
// ...
plugins {
if (Environment.current == Environment.DEVELOPMENT) {
// ... conditional parts for dev
}
// always...
}

How to force Grails to use a signed certificate with run-app or run-war

Even after adding this code to Config.groovy, Grails insists on using its own self-signed certificate:
grails.tomcat.truststorePath = "${grailsSettings.baseDir}/conf/ssl/truststore.jks"
grails.tomcat.truststorePassword = "changeit"
grails.tomcat.clientAuth = "want"
grails.tomcat.keystorePath = "${grailsSettings.baseDir}/conf/ssl/keystore.jks"
grails.tomcat.keystorePassword = "changeit"
grails.tomcat.keyAlias = "localhost"
Any idea how to force Grails to use the real keystore here?
Apparently, it's a common mistake to put these settings in Config.groovy. They belong in BuildConfig.groovy. Once I put them in BuildConfig.groovy, everything worked for me.
I couldn't get your example to work or figure out how to set any properties in BuildConfig.groovy, but for grails 2.5.0 this worked for me in scripts/_Events.groovy.
eventConfigureTomcat = { org.apache.catalina.startup.Tomcat tomcat ->
if (Environment.getCurrent() == Environment.DEVELOPMENT) {
System.setProperty("javax.net.debug", "ssl") //use this to confirm grails adds proper keystore/truststore settings
System.setProperty("javax.net.ssl.keyStoreType", "jks")
System.setProperty("javax.net.ssl.keyStore", "/absolute/path/to/keystore")
System.setProperty("javax.net.ssl.keyStorePassword", "<_password_>")
System.setProperty("javax.net.ssl.trustStoreType", "jks")
System.setProperty("javax.net.ssl.trustStore", "/absolute/path/to/truststore")
System.setProperty("javax.net.ssl.trustStorePassword", "<_password_>")
println "SSL configuration complete"
}
}

Grails auto-reloading new controller actions

I've
created new Grails 2.4.3 project
created TestController
set grails.reload.enabled = true in BuildConfig.groovy
run application with grails -reloading run-app
My controller action code:
def index() {
render "test"
}
When I change the string test to test2- I see in console (in Eclipse):
..................
|Compiling 1 source files
And after reloading page I see test2 - ok.
But when I try to add new method:
def test3() {
render "test3"
}
I see:
Why? Why there isn't even the url?
Example - action does't exist:
Interesting thing is - when I create a whole new controller the index action of the newly created controller works...
EDIT
After a while I decided to go with spring-boot and as a matter of fact - there it's not working either. I think that springloaded is the issue here because it doesn't pick up added new method in #Controller
I've asked the same question on github repo.
It seems that latest spring-loaded SNAPSHOT is working fine.
But it must be integrated into Grails - maybe in the next release unfortunately :(
Solution that works for me:
1) Versions:
IDE: Intellij IDEA 14.1.3
JDK: jdk1.7.0_25
GRAILS: 2.5.0
2) On BuildConfig.groovy:
grails.reload.enabled = true
grails.project.fork = [
test: false,
run: false,
]
3) Originally, my code was compiled on grails 2.4.4, so I upgraded to 2.5.0. I had no problems with the version change with plugins or anything. My guess is this works because it uses later versions of spring-loaded. Steps:
set-grails-version 2.5.0
clean
delete directory work (just to be sure, I don't really know if this is good practice)
compile and/or go to number 4
4) Debug Idea with this configuration: run-app -reloading
Works perfect, no forked debug, reloading enabled, no console error after reload and all breakpoints working even after code changes!
I took the liberty of reporting this issue to Grails.

Resources