Grails 4 hot swap / recompile - spring

Im using:
Intellij
grailsVersion: 4.0.3
gorm.version: 7.0.4.RELEASE
I just get:
Testcontroller.groovy changed, recompiling...
But my code isn't hot deployed.
With Grails 3 everything worked fine.
What can I do so that the Controllers in Grails 4 and Spring Boot 2 get hot deployed?

You may use spring-loaded (project has been idle for years but still works) or JRebel for "hot" reloads.
To enable:
build.gradle
dependencies {
// Remove dev-tools from classpath
// developmentOnly("org.springframework.boot:spring-boot-devtools")
agent "org.springframework:springloaded:1.2.8.RELEASE"
// (Optional) Native OSX file watcher
runtimeOnly "io.methvin:directory-watcher:0.9.6"
//...
}
See: https://github.com/grails/grails-core/pull/11441

well solved forgot in build.gradle:
developmentOnly("org.springframework.boot:spring-boot-devtools")
It's very slow compared to the old Spring boot but works as indeed.

We found a solution for grails 4.0.13 similar to #erichelgeson
you found it here: https://github.com/grails/grails-core/issues/11649#issuecomment-1085910706
bootRun {
jvmArgs(
// javaagent: see
// - https://github.com/grails/grails-core/issues/11649
// - https://github.com/spring-projects/spring-loaded
// - find the jar here: https://repo.spring.io/ui/repos/tree/General/libs-snapshot-local/org/springframework/springloaded
"-javaagent:libs/springloaded-1.3.0.BUILD-20210404.024037-2.jar",
// ...
}
Here the links from the comment block:
https://github.com/grails/grails-core/issues/11649
https://github.com/spring-projects/spring-loaded
find the jar here: https://repo.spring.io/ui/repos/tree/General/libs-snapshot-local/org/springframework/springloaded

Related

Gradle Idea plugin - issues with specifing test sources

I'm trying to create a custom source set and mark its contents in Intellij Idea as a Test Sources Root. I tried to use idea plugin and do it according to the gradle official website but it is not clear for me how it works.
First of all the documentation specifies the following configuration setup
idea {
module {
testSources.from(sourceSets["intTest"].java.srcDirs)
}
}
When I try to use it i receive Unresolved reference: testSources. Where is it coming from?
Then I tried to use:
idea {
module {
testSourceDirs = intTest.java.srcDirs
}
}
it works fine as long as I use only Java. After applying Kotlin plugin however, both kotlin and java + resources folder are again treated as Sources Root not Test Sources. To fix that I had to change from:
testSourceDirs = intTest.java.srcDirs
to:
testSourceDirs = intTest.kotlin.srcDirs
and now all folders are Test Source Root again. Since kotlin.srcDirs also includes java.srcDirs it looks like you have to specify all, otherwise it is ignored...
Now the real issue came when I used gradle-avro-plugin. Applying it made my folders marked as Sources Root again. I believe it is because it adds another avro directory, but just to main source set.
Does anyone know how to make it marked as Test Sources having both kotlin and avro plugin applied? Am I doing something wrong here? Beacause this beheviour seems to be buggy in the first place.
Tested with:
IntelliJ IDEA 2022.3.1 (Ultimate Edition)
Gradle 6.8.3 and 7.4.2
Plugin id("com.github.davidmc24.gradle.plugin.avro") version "1.5.0"
Plugin kotlin("jvm") version "1.7.0"

Vaadin 8 - widgetset

I added Vaadin google maps addon to my Spring boot project. If I want to display map on site, then I get error:
Widgetset 'com.vaadin.DefaultWidgetSet' does not contain an
implementation for com.vaadin.tapio.googlemaps.GoogleMap. Check the
connector's #Connect mapping, the widgetset's GWT module description
file and re-compile your widgetset. In case you have downloaded a
vaadin add-on package, you might want to refer to add on instructions
If I add #Widgetset("com.vaadin.v7.Vaadin7WidgetSet") annotation to UI class, then I get this error:
Failed to load the widgetset:
./VAADIN/widgetsets/com.vaadin.v7.Vaadin7WidgetSet/com.vaadin.v7.Vaadin7WidgetSet.nocache.js?1521722356809
And I have a question: How should a widgetset look like, how to build it? I was looking for examples and tutorials but I still can't do this.
I read that in early Vaadin versions, I should do a manual compilation widget, but in version 8 compiling is automated.
Maybe this is important information, but I use gradle not maven.
Please help me, because I am trying to fix it for a week.
As soon as you include add-ons in your Vaadin project, you need to compile the widgetset and the widgetset needs to include the add-on widgetsets.
I have the following src/main/resources/widgetsets/AppWidgetset.gwt.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Vaadin//DTD Vaadin 7//EN" "https://raw.github.com/vaadin/gwt/master/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.vaadin.DefaultWidgetSet"/>
<!-- include widgetsets of external add-ons here -->
<inherits name="org.vaadin.hene.popupbutton.widgetset.PopupbuttonWidgetset"/>
</module>
This includes the Vaadin PopupButton add-on. Of course you need to adapt it to include your desired add-ons. My gradle build looks like:
configurations {
vaadinAddOns
widgetSetCompilation
themeCompilation
}
dependencies {
themeCompilation('com.vaadin:vaadin-spring-boot-starter')
}
task compileWidgetSet(type: JavaExec) {
// execution of Vaadin GWT compiler
classpath configurations.vaadinAddOns
classpath configurations.widgetSetCompilation
classpath file("${projectDir}/src/main/resources/widgetsets")
main = 'com.google.gwt.dev.Compiler'
args '-war', "${projectDir}/src/main/resources/VAADIN/widgetsets"
args '-strict'
args '-logLevel', 'WARN'
args 'AppWidgetset'
jvmArgs '-Xmx1024M'
doLast {
// clean up unnecessary stuff
file("${projectDir}/src/main/resources/VAADIN/gwt-unitCache").deleteDir()
file("${projectDir}/src/main/resources/VAADIN/widgetsets/WEB-INF").deleteDir()
}
// for the up-to-date check of gradle
outputs.dir("${projectDir}/src/main/resources/VAADIN/widgetsets/AppWidgetset")
}
clean.dependsOn cleanCompileWidgetSet
processResources.dependsOn compileWidgetSet
// on-the-fly theme compilation is disabled in Vaadin production mode, so we do the compilation ourselves
task compileThemes {
def themesFolder = file("${projectDir}/src/main/resources/VAADIN/themes")
new FileNameFinder().getFileNames(themesFolder.toString(), '**/styles.scss').each { path ->
def themeFolder = file(path).getParentFile()
def fileIn = new File(themeFolder, 'styles.scss')
def fileOut = new File("${buildDir}/resources/main/VAADIN/themes/${themeFolder.getName()}/styles.css")
dependsOn tasks.create("compileTheme${themeFolder.getName().capitalize()}", JavaExec) {
classpath configurations.themeCompilation
main = 'com.vaadin.sass.SassCompiler'
args fileIn, fileOut
inputs.dir(themesFolder)
outputs.file(fileOut)
}
}
}
processResources.dependsOn compileThemes
And finally the annotation:
#Widgetset("AppWidgetset")
public class MyUI extends UI {
...
}
This is a lot of manual stuff. You can omit the theme compilation if you do not run in Vaadin production mode for now. I am almost sure that there is a Vaadin gradle plugin out there that simplifies the widgetset and theme compilation but when I was looking for it it didn't match my requirements.
Btw: Vaadin 7 widgetset is not appropriate for Vaadin 8 :)
I sounds like your project is missing build setup for Vaadin extensions requiring client side extensions (aka custom widgetset). This happens often with new Spring users as start.spring.io don't currently support adding third party Maven plugins. Addin vaadin-maven-plugin and doing full build should fix the issue.
To see a Spring Boot project with vaadin-maven-plugin configured, I suggest to use the viritin-spring-archetype and see the generated project (and especially the pom.xml generated by the project). You can also manually copy the relevant parts from the official plain servlet project template (generated by the default archetype or IDE plugins).
When using Gradle the fix is similar in nature. If you created the project using start.spring.io, you can just add the gradle-vaadin-plugin to your project, by adding follow snippet to your build.gradle file, e.g. after buildScript section:
plugins {
id 'com.devsoap.plugin.vaadin' version '1.3.1'
}
You will also need to declare dependencies with client side extensions as follows (use google maps coordinates instead):
vaadinCompile("org.vaadin.addon:v-leaflet:2.0.6")

Grails 3 - How to publish to Artifactory

I have several Grails 3 projects. Most are plugins and one is the main app that depends on the plugins.
Can someone who has successfully published a Grails 3 project to an Artifactory repo tell me how you did it? What gradle plugin do you use and what do you need to add to your build.gradle to make it work?
Regards,
Rob
I blogged the answer:
http://rvanderwerf.blogspot.com/2015/07/how-to-publish-grails-3-plugin.html
Basically you need to strip out anything in the POM with no version on it as Grails/Boot managed those deps.
I just started working with grails 3, specifically version 3.2.8.
I found that placing the following entry at the end of build.gradle works where artifactory_user, artifactory_password, artifactory_snapshotUrl, and artifactory_releaseUrl are defined in gradle.properties.
publishing {
repositories {
maven {
credentials {
username artifactory_user
password artifactory_password
}
if (version.endsWith('SNAPSHOT')) {
url artifactory_snapshotUrl
} else {
url artifactory_releaseUrl
}
}
}
}
File gradle.properties reads:
grailsVersion=3.2.8
grailsWrapperVersion=1.0.0
gormVersion=6.0.9.RELEASE
gradleWrapperVersion=3.4.1
app_version=0.0.1-SNAPSHOT
artifactory_user=admin
artifactory_password=password
artifactory_contextUrl=http://myserver.myorg.org:8081/artifactory
artifactory_snapshotUrl=http://myserver.myorg.org:8081/artifactory/libs-snapshot-local
artifactory_releaseUrl=http://myserver.myorg.org:8081/artifactory/libs-release-local

Android Studio with Java Library Module Unable to load test resources

I have an Android Studio Project with a Java library inner module that has tests with test resources. Yet when i run the tests I am not able to retrieve the artifacts. This seems to work fine in a pure java gradle project (in eclipse at least).
meaning For java plugin:
src/main/java
src/main/test
src/test/java
src/test/resources
Under the resources directory i have a crt file that i want to load in my junit test. When using any command i have come across it returns null for the resource. Yet I have confirmed the resources are in the build folder.
Some things I Tried:
getClass().getClassLoader().getResourceAsStream("cert_format_der.crt").read(); // NPE
getClass().getClassLoader().getResourceAsStream("/cert_format_der.crt").read(); // NPE
getClass().getClassLoader().getSystemResourceAsStream("/cert_format_der.crt").read(); // NPE
Thanks
Turns out this seems to be a bug with Intellij and how Gradle not setting the resource directory for the test sourcesets correctly.
Adding This to the build.gradle for the module Fixes it:
sourceSets {
test {
output.resourcesDir = output.classesDir
}
}
Instead of diverging the resources to the class output directory − as suggested by nibbuen − it is also possible not to touch the output directory and explicitly add it as a dependency.
dependencies {
runtime files(sourceSets.test.output.resourcesDir)
}

Trouble Installing/Using Grails Release Plugin 2.2.1

I'm trying to get the Grails release plugin to work, but running into some trouble. The current version of Grails that ships with STS/GGTS is 2.2.3, so I can't use the most recent version (3.0) of the release plugin because that requires Grails 2.3. Instead, I tried to install version 2.2.1.
I started by adding the following to my BuildConfig.groovy and refreshed my dependencies.
plugins {
... // other plugin dependencies
build ':release:2.2.1', ':rest-client-builder:1.0.3', {
export = false
}
... // other plugin dependencies
}
but I got the following error when I ran grails maven-install
| Script 'MavenInstall' not found, did you mean:
1) UninstallPlugin
2) InstallPlugin
3) InstallDependency
4) InstallJQuery
5) InstallTemplates
.
.
LOTS OF TROUBLE SHOOTING DETAILS FOLLOW.
YOU CAN JUST SKIP TO PETER'S ANSWER BELOW
.
.
Then, I found this JIRA issue, and I listed my plug-ins and release was not install, so I tried
grails install-plugin release 2.2.1
and refreshed my dependencies and I ended up with a compilation error in GrailsCentralDeployer. It could not find grails.plugins.rest.client.RestBuilder, so I ran
grails install-plugin rest-client-builder 1.0.3
and refreshed my dependencies and the error went away. At this point, I'm not sure if the code I added to BuildConfig.groovy is actually doing anything.
Now, when I run
grails maven-install --stacktrace
I get the following
| Loading Grails 2.2.3
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Error Error executing script MavenInstall: java.lang.ClassNotFoundException: grails.plugins.publish.DistributionManagementInfo (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.ClassNotFoundException: grails.plugins.publish.DistributionManagementInfo
If it helps, here are the contents of my BuildConfig.groovy
removed - refer to edit 2 below
EDIT 1
This is my was application.properties file
#Grails Metadata file
#Thu Jul 25 07:05:41 EDT 2013
app.grails.version=2.2.3
app.name=swiper-admin
app.version=0.1
plugins.spring-security-cas=1.0.5
plugins.spring-security-core=1.2.7.3
plugins.spring-security-ldap=1.0.6
I moved the security plugins from here to BuildConfig.groovy and everything worked fine, so the new file looks like this
#Grails Metadata file
#Thu Jul 25 07:05:41 EDT 2013
app.grails.version=2.2.3
app.name=swiper-admin
app.version=0.1
and my new BuildConfig.groovy looks like this.
removed - refer to edit 2 below
I ran grails clean and then grails compile and the grails maven-install and got the same ClassNotFoundException: grails.plugins.publish.DistributionManagementInfo
I then ran grails list-plugins --installed and this is the output
removed - refer to edit 2 below
Edit 2
#peter-ledbrook, Before, I saw your advice, I have freshly cleaned the project. I added grails.project.work.dir = "target" to my BuildConfig.groovy then ran the following
user#computer:~/dev/workspace/swiper-admin$ grails clean
| Application cleaned.
user#computer:~/dev/workspace/swiper-admin$ grails refresh-dependencies
| Dependencies refreshed.
user#computer:~/dev/workspace/swiper-admin$ grails maven-install
| Script 'MavenInstall' not found, did you mean:
1) UninstallPlugin
2) InstallPlugin
3) InstallDependency
4) InstallJQuery
5) InstallTemplates
> Please make a selection or enter Q to quit: Q
user#computer:~/dev/workspace/swiper-admin$ grails compile
| Compiling 143 source files
| Compiling 27 source files.
user#computer:~/dev/workspace/swiper-admin$ grails maven-install
| Script 'MavenInstall' not found, did you mean:
1) UninstallPlugin
2) InstallPlugin
3) InstallDependency
4) InstallJQuery
5) InstallTemplates
> Please make a selection or enter Q to quit: Q
user#computer:~/dev/workspace/swiper-admin$
My BuildConfig.groovy looks like this
grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
grails.project.war.file = "${appName}-${appVersion}.war"
grails.project.work.dir = "target"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") { }
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenLocal()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies { }
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.2"
build ":tomcat:$grailsVersion"
build ':release:2.2.1', ':rest-client-builder:1.0.3', { export = false }
compile ':cache:1.0.1'
compile ":db-reverse-engineer:0.5"
//security
compile ":spring-security-core:1.2.7.3"
compile ":spring-security-cas:1.0.5"
compile ":spring-security-ldap:1.0.6"
}
}
grails.project.repos.atlassian_nexus.url = "https://atlassian.liberty.edu/nexus/content/groups/public"
grails.project.repos.atlassian_nexus.username = "terskine"
grails.project.repos.default = "atlassian_nexus"
and grails list-plugins --installed look like this
| Loading Grails 2.2.3
| Configuring classpath.
| Environment set to development.....
Plug-ins you currently have installed are listed below:
-------------------------------------------------------------
cache 1.0.1 -- Cache Plugin
db-reverse-engineer 0.5 -- Grails Database Reverse Engineering Plugin
hibernate 2.2.3 -- Hibernate for Grails
jquery 1.8.3 -- JQuery for Grails
resources 1.2 -- Resources
spring-security-cas 1.0.5 -- Jasig CAS support for the Spring Security plugin.
spring-security-core1.2.7.3 -- Spring Security Core Plugin
spring-security-ldap1.0.6 -- LDAP authentication support for the Spring Security plugin.
tomcat 2.2.3 -- Apache Tomcat plugin for Grails
webxml 1.4.1 -- WebXmlConfig
To find more info about plugin type 'grails plugin-info [NAME]'
To install type 'grails install-plugin [NAME] [VERSION]'
For further info visit http://grails.org/Plugins
Edit The problem is the export = false. Remove that. I don't understand why it's preventing the installation of the plugin, so it's possibly a bug in Grails. Raise an issue in the Grails JIRA.
Previous answer
What you're doing looks fine. I would simply add this line to the beginning of BuildConfig.groovy:
grails.project.work.dir = "target"
Save that and then run
grails refresh-dependencies
grails maven-install
Any time there seem to be strange class-related errors, simply delete the whole of the target directory.
Don't use install-plugin, it's deprecated and removed entirely in 2.3.
You were correct to use BuildConfig.groovy - after saving the change you just need to run grails compile or some other commandline script that triggers dependency resolution. This will install any missing plugins and their dependencies, and report any errors.
Note that since you ran install-plugin you probably have cruft in application.properties - be sure to delete any lines in there that refer to installed plugins. For a plugin you can delete everything except for
app.grails.version=2.2.3
Your BuildConfig.groovy looks a bit weird, more of an application type of file than a plugin. You don't need grails.servlet.version, grails.project.target.level, grails.project.source.level, grails.project.war.file. Also I like to keep things simple and move everything to the target folder with the grails.project.work.dir property.
And do you really need all of those plugin dependencies? They make sense in an application, but not in a plugin unless your plugin really does need them:
grails.project.work.dir = "target"
grails.project.dependency.resolution = {
inherits 'global'
log 'warn'
repositories {
grailsCentral()
mavenLocal()
mavenCentral()
}
dependencies {
}
plugins {
build ':release:2.2.1', ':rest-client-builder:1.0.3', { export = false }
}
}
grails.project.repos.foo.url = "https://server.domain.edu/nexus/content/groups/public"
grails.project.repos.foo.username = "bar"
grails.project.repos.default = "foo"

Resources