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.
Related
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)
I am trying to do a simple background job in Grails. I just want stuff to happen every 30 seconds or so.
I am using Grails 3.1.3
I've added Quartz to my dependencies:
compile "org.grails.plugins:quartz:2.0.1"
Then I've run a compile and restarted the grails CLI. Now I created a Job via create-job. It looks like this:
package htwp
class UserSyncJob {
static triggers = {
simple repeatInterval: 5000l // execute job once in 5 seconds
}
def execute() {
println ("?")
log.error("??!")
throw new Error("JOB WHERE ARE YOU");
}
}
Nothing happens when I start the server via run-app. Nothing printed, no errors either.
What am I doing wrong?
I checked issues of quartz plugin for Grails project and found this issue and this issue.
Just upgrade as I said earlier in comment to the newest realese of plugin.
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" }
I just grabbed the latest version of the functional testing plugin and it's focus, at least from the docs, has changed a bit. This is not a bad thing. The HtmlUnit integration is nice. But now, there isn't anything in the docs about RESTful testing of web services. However, what I used to do with functionaltestplugin.FunctionalTestCase still works, which is great.
For example:
void testCertifyEmployerCertifierNotFound() {
post('/employerCertification/certifyEmployer') {
headers['Content-Type'] = 'application/json'
body {
"""
{
'employerName': 'ACME',
'certifierExteralId': '1234556',
'certifyingUserId': '123445'
}
"""
}
}
assertStatus 200
assertContentType "application/json"
def model = this.response.contentAsString
def map = JSON.parse(model)
assertFalse(map.success)
assertNotNull(map.errorCode)
assertTrue(map.errorCode == EmployerCertificationService.ERROR_RESPONSE.CERTIFIER_NOT_FOUND.toString())
}
Is this plugin still the "defacto" plugin to use for functional web service testing and is my approach above still valid?
if your target is testing REST request/response I suggest you to use rest client builder plugin. You don't need complex browser-simul plugins. Use it is very simple in just two steps after installing it:
add event to manage functional tests in scripts/_Events.groovy: this is a system grail file used to hook some events at runtime. Just copy and paste this snippet:
eventAllTestsStart = {
if (getBinding().variables.containsKey("functionalTests")) {
functionalTests << "functional"
}
}
Now you can create functional tests in test/functional folder, rememeber to ends filename with Spec, grails will not find any tests if you forget this.
This is an example:
import grails.plugins.rest.client.RestBuilder
import spock.lang.Specification
class AuthenticationSpec extends Specification {
String baseUrl = "http://localhost:8080/grouply-backend"
void "test login wrong credentials"() {
given:
RestBuilder restBuilder = new RestBuilder()
when: "sending wrong credential"
def response = restBuilder.post("${baseUrl}/auth/login") {
json {
username = 'foo'
password = 'bar'
}
}
then: "authentication http error should happen"
response.status == 401
}
}
run tests with $ grails test-app functional:
I have just tried to use both functional testing plugin and webtest plugin with almost-current Grails 2.4.2 and I am sad to report that they are both borked. :(
Functional testing plugin has been practically abandoned for at least 9 months now. On December 2013 a critical bug that makes all of tests written using this plugin not working has been reported. There was no response from plugin developer regarding it up to the day I am writing this. And as this developer, Marc Palmer has switched to iOS development and consultancy in August 2014 I don't believe this bug will ever be resolved.
Webtest plugin has been last updated more than 3 years ago and it "requires Grails 1.2.RC2+". I run into ugly error of missing webtest.jar when running it and it looks like this plugin just haven't been updated to current Grails version. Also its syntax is not very Groovy-like and not nice.
Fortunately Geb integration for Grails plugin is supposed to work with current Grails versions. :) In fact in does only work with Grails 2.3.1+, as of writing these words has been last time updated in June 2014 and it's example tests project have been updated to Grails 2.4.3, release just a few days ago already, so it is very up-to-date. However I haven't used this project yet. Also looking at is's example code I am not sure it the best choice for RESTful API testing - it's more of a GUI web application testing tool..
Although is probably not very "grails style" i guess it should be possible to start up the whole stack with the spring context and run integration rest tests using apache HttpClient.
I make a brand new grails project and put this in the bootstrap:
ExpandoMetaClass.enableGlobally()
Integer.metaClass.precision = {->return 1}
println 3.precision()
println "rofl"
println 15.precision()
And it does what I expect, run-app prints:
1
rofl
1
But if i take out the println "rofl" it won't print that second one. It just prints one 1 without the rofl... WTF?
Again, becasue this doesn't make any sense to me, this code:
ExpandoMetaClass.enableGlobally()
Integer.metaClass.precision = {->return 1}
println 3.precision()
//println "rofl"
println 15.precision()
prints:
1
Mikey, I can't think of a reason why. Can you try in a different environment? I just tried this quickly under Groovy Version: 1.8.0 JVM: 1.6.0_20, Win7 and Grails 2 BootStrap and a Grails Controller action and sorry to say "it works on mine". So all I can think is that its somehow related to the version you are using or how it is setup. How are you running this?
This is an ubuntu default setting and has nothing to do with JVM. The console won't repeat lines if they are the same. Will update this answer when I remember how to turn it off.