Grails 4 and Views-Json 2 : Build fails - grails

I'm trying to upgrade a Grails app from 3.3 to 4 (specifically 4.0.3 for now) and the Views-Json 2.0.2 plugin. Profile is angular.
When I run the app in development mode everything works. However when I attempt to build using gradlew :server-api:assemble the build fails at the Task :server-api:compileGsonViews (yeah, renamed 'server' to 'server-api' for clarity).
It looks like it's not finding my Java classes (there are a few under src/main/java).
I've see refs to setting the classpath for the compileGsonViews, but I was undable to make it work.
Anyone with suggestions?
Running on Windows 10 with latest OpenJDK 1.8.x

Somehow I seem to have stumbled on the solution. In my build.gradle I had enabled the grails pathingJar, commenting that out allowed my war to build. However with the property commented out, I was unable to use the gradlew bootRun command as it failed due to the path being too long.
The solution (for me) was to add a build property, the build file then looks like:
def usePathing = Boolean.valueOf( System.getProperty('pathingJar', 'false') )
if (usePathing) {
grails {
pathingJar = true
}
}
If I was better with gradle I think I could (maybe) determine the goal that is being targeted and use that, but the above works. The commend to assemble the war is the same; but to run the app directly I need to make it gradlew server-api:bootRun -DpathingJar=true

Related

How to run Spock unit tests without intializing Grails environment

I have a Spock unit test in a Grails app. In IntelliJ IDEa I can either run it with grails environment and then it means I wait a minute until the environment loads to run the test even though I do not need the environment.
The other option is to run it with JUnit. This works nicely in a Grails app without my own plugins. However, when I run it in a Grails app that has a plugin of another Grails app I have, it crashes on NoClassFound. It does not see the classes from the plugin that I included.
When I checked in IDEa the project structure, indeed the sources nowhere include a folder where the plugin classes would be included. For some reason the plugins in plugins section in BuildConfig.groovy do not appear in the classpath anywhere, they are not found in the external libraries section or anywhere else.
Is there a way to tell grails not to spin up its environment when running some of my tests? Or how can I include my plugin in the classpath for Groovyc to see it when building for testing?
The problem occurs also when simply pressing Build Project in IntelliJ IDEa. The project we are working with is simply run with grails and is never built (beyond how grails builds it). When you try to build it in IDEa, it fails on NoClassDefFound of plugin class.
Versions:
IntelliJ IDEa 2021.2
Grails 2.5.6
EDIT: Ok, it seems like grails apps are to be tested via their command-linke with grails test-app. When Grails runs in interactive mode, test-app won't have to reinitialize the environment, cause it's already running, so it runs faster.
However, as I found here Slow Grails test starting in Intellij IDEA it seems like there's no way to run grails in interactive mode from within IDEa in a way that would enable IDEa test runs to use such interactive console. Which means I'm forced to run tests via command-line. Not happy.
Edit 2: At some point in time I have managed to get the compiled tested.class to the out folder. This enabled running the test instantly via IDEa circumventing the Grails glory. However, I have no idea how I got it to out folder and after removing it I am unable to compile it again and get it there.

Grails 3, how to run projects which had an older grails version

here is a grails project, but if you have grails 3.3 installed, and try to run it with "grails run-app" it throws the error:
| Error Error initializing classpath: Unsupported method: GrailsClasspath.getError().
The version of Gradle you connect to does not support that method.
Any ideas how to run it? Do I have to find, install, then change my paths to point to the old version, or is there some other way using gradle?
I see there is something called gradlew.bat, but looking through the grails docs, it doesnt say how to use it. is gradlew.bat like the grails command line, and, if so, where is it documented on how to use it?
Any ideas how to run it?
./gradlew bootRun
Do I have to find, install, then change my paths to point to the old
version, or is there some other way using gradle?
No, you don't have to install Gradle and you don't have to do anything with your PATH. That is the point of the wrapper (gradlew).

Grails GEB Tests Fails On Subsequent Runs

My application uses the following versions:
Geb: 0.9.2
Selenium: 2.26.0
Grails: 2.1
Spock: 0.7
And I'm running on a linux box with the following:
Firefox: 14
Centos: 5.3
I have a grails application and I am using Geb in the functional test phase.
If I'm starting from a clean environment (.grails has been wiped) and I run my tests they all go through fine, geb runs up firefox, does the tests and gives me the report.
However subsequent runs of the functional tests all tests will fail with:
geb.giver.DriverCreationException
which is apparently caused by:
java.lang.NoSuchMethodException
Now if I trash my .grails and run again, the next time the pass fine. Just want to be able to run the tests consistently.
Any help would be greatly appreciated!
Cheers
UPDATE:
Below is the gist of the stack trace (copied by hand so apologies for any typos):
geb.driver.DriverCreationException: failed to create driver from callback 'GebConfig$_run_closure#6f61a3c4'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CalbackDriverFactory.getDriver_closure3(CachingDriverFActory.groovy:80)
...
Caused by: java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/string;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:48)
at org.openqa.selenium.remote.HttpCommandExecuter.<init>(HttpCommandExecuter.java:118)
...
I had this exact issue in the past. Exactly with HttpDriver classes in the stacktrace and happening on the second run after a clean. It's due to some of your Grails plugins pulling in a conflicting version of HttpClient.
I found that it's usually a plugin that transitively pulls in the release plugin but doesn't exclude it from exporting. The way to find the culprit is to go through all of your installed plugins for that app in your .grails directory and looking at their dependencies to find the one that is pulling the release plugin in and then either remove it or update it to a newer version as more and more plugin authors are excluding release plugin from exporting and I also believe that latest versions of release plugin don't depend on HttpBuilder anymore.

Set a different classpath for just one grails command

I need to set a different classpath for one single grails xxx command.
The point is that my application uses latest version of commons-httpclient. I have no problems with this. But after building my application I need to use grails maven-deploy to store my war file in a webdav repository, and the command conflicts with the latest version of commons-httpclient. This command works great if I add commons-httpclient-2.0.2.jar in the classpath (lib folder for example), but the app will fail on trying to use the regular features that depends on commons-httpclient.
I need to add this other jar in the classpath just for running the maven-deploy command, any ideas?
I'm using jenkins (huson) to build the app, so, any tips on making the solution achievable with grails jenkins plugins will be appreciated.
Thanks a lot,
Does the grails maven-deploy command conflicts due to another dependency on httpclient?
Which one is it? May be you could exclude the dependency it?

Grails and hudson plugin issue

I'm developing my first project in Grails framework. I'm using Spring Security Core plugin. On my machine, on newest IntelliJ Idea everything works fine. I can run, test and so on with no problems.
I have a remote machine with subversion where I upload my code and Hudson with Grails Plugin. Target which I call on my hudson builds is:
"test-app --non-interactive"
When I run build, everything goes fine - plugins are downloaded and then, bam!
Resolving plugin JAR dependencies ...
:: UNRESOLVED DEPENDENCIES :: ::::::::::::::::::::::::::::::
:: org.springframework#org.springframework.test;3.0.5.RELEASE: configuration not found in org.springframework#org.springframework.test;3.0.5.RELEASE: 'master'. It was required from org.grails.internal#League;0.1 test
Here I put whole output from Hudson Console of this project build.
That looks like a dependency issue with the Mail plugin, try going back to a non-snaphot version. I think 1.0 will be out shortly but see if 0.9 works.
Grails will automatically install the plugins it needs, you don't need to do anything manual on the build server.
You have to install the plugin of the remote machine. Because the plugins are not included in the code. The plugin will be installed under your_home/.grails/grails_version/plugins (or project/your_project).

Resources