Versions of plugins + jars at runtime Grails - grails

Is it possible to find out what versions of the various plugins that are in my war / class loader at runtime? The reason I want to do this so that I can be 100% sure at runtime what version of what is in production.
I see a mechanism in this thread: Obtain Grails plugin version at runtime
But was wondering how I would get this in a GSP? Also, this does not give me the jar versions. Thanks

Can't get it for jars but to display in GSP, do...
controller:
class MetaController {
def pluginManager
def plugins
def index() {
log.debug(">>index()")
// retrieve them all...
plugins = pluginManager.allPlugins.collect { plugin ->
log.debug("Plugin: ${plugin.name}, Version: ${plugin.version}")
return "Plugin: ${plugin.name}, Version: ${plugin.version}"
}
plugins.sort()
[plugins: plugins]
}
}
View...
...
<g:each in="${plugins}" var="p">
<li>${p}</li>
</g:each>

Related

Expression codec (grails.views.gsp.codecs.expression) seems to be ignored in deployed war file

In a fresh grails 4.0.4 application the settings of
grails:
views:
gsp:
codecs:
expression: none
seem to be ignored when deployed as a war file in a Tomcat 8.5.39. (JVM 11.0.7+10-post-Ubuntu-2ubuntu218.04)
Adding this
<head>
...
<script>
var foo = ${[a:23, b:42, c:666] as grails.converters.JSON};
</script>
</head>
to the generated grails-app/views/index.gsp shows up as
var foo = {"a":23,"b":42,"c":666};
when running grails run-app or even grails prod run-app(!), but is encoded as
var foo = {"a":23,"b":42,"c":666};
in the packaged (grails prod war) deployed war file.
The build.gradle was unmodified, except for changing
compile "org.grails.plugins:cache"
to this
compile("org.grails.plugins:cache") {
exclude module:'groovy-all'
}
Is this a bug or am I using the codecs settings wrong? Maybe there is a plugin overwriting this settings (like here https://github.com/grails/grails-core/issues/10722) but i cannot find any other yml files. Any help is appreciated!
It works like a charm in Grails 4.0.3. Seems it is broken in Grails 4.0.4 ...
Maybe the problem came with the new Groovy Page Compiler Task. The config file (aka application.yml) variable here is never used. But that's only an assumption after quick investigation with too little coffee ;-)
Workaround or my preferred way (still working in Grails 4.0.4)
Some helper TagLib like this:
import grails.converters.JSON
class FooTagLib {
static defaultEncodeAs = [taglib:'none']
static namespace = "foo"
def json = { attrs, body ->
out << raw(attrs.data as JSON)
}
}
Usage:
var foo = <foo:json data="[a:23, b:42, c:666]"/>

Fontawesome resource plugin error

I want to use fontawesome plugin in grails.
I have added in build config compile :font-awesome-resources:4.0.3.1 to add plugin.I have added
customBootstrap
{
dependsOn 'font-awesome'
resource url: 'css/bootstrap.css'
resource url: 'js/bootstrap.js' resource url: 'css/bootstrap-fixtaglib.css'
}
in applicationresource.groovy but when i run the application get error
ERROR resource.ResourceProcessor - Unable to load resources Message: No such property: pluginManager for class: org.springframework.web.context.support.XmlWebApplicationContext.Please provide solution.
I am not sure whether this is a configuration issue with migration from earlier grails versions or if font-awesome has not been migrated completely to grails 2.4.x. But I encountered this as well.
As a short (dirty) workaround, you can replace the code that causes the problem directly on the plugin.
File (replace X with your project name):
~/.grails/2.4.2/projects/X/plugins/font-awesome-resources-4.0.3.1/grails-app/conf/FontAwesomePluginResources.groovy
Replace lines 3 and 4 with:
def pluginManager = grails.util.Holders.pluginManager
def lesscssPlugin = pluginManager.getGrailsPlugin('lesscss-resources') || pluginManager.getGrailsPlugin('less-resources')
And give it a go.

Grails Jquery-ui plugin configuration

Trying to use the Jquery-UI plugin from http://grails.org/plugin/jquery-ui
but apparently the documentations is not correct when discuss using the plugin with resources framework as following the instructions leads to an error:
Error processing GroovyPageView: Error executing tag <r:layoutResources>: No module found with name [jquery-ui]
Apparently the same problem is known around, but was not able to find a solution on the net (example: some discussion here and some other discussions with no solution or hints to a solution).
Did anyone managed to successfully configure jquery-ui in grails with the resource framework?
First you need to install the plugin, so in your BuildConfig.groovy
plugins {
...
compile ":jquery-ui:1.8.24"
...
}
Use grails compile --refresh-dependencies and see if the console output the download of the plugin. If you are using STS, you can go in right click > grails tools > refresh dependencies
After that, you can add <r:require module="jquery-ui"/> before the <r:layoutResources/>
A usefull tip is the change of the jquery ui theme, you can configure this in your ApplicationResources.groovy
modules = {
overrides {
'jquery-theme' {
resource id:'theme', url:'/css/ui/jquery-ui-1.8.21.custom.css'
}
}
}
In this example i have one css located in web-app/css/ui/.
Another tip is that you can force your modules to depend on jquery-ui:
modules = {
mymodule {
dependsOn 'jquery-ui'
resource url: '/js/my.js'
}
}
So if you add the resource mymodule to your GSP, the jquery-ui will be loaded too.

How build Vaadin project with gradle?

I have gradle project (backend) and I want to add Vaadin-based frontend. But I haven't find any gradle-plugins for Vaadin.
While, as was already mentioned above, Vaadin app is a simple web application and does not require any additional plugins but "java" and "war" (and maybe "jetty" to run the app), currently there seems to be the first vaadin-specific gradle plugin available:
https://github.com/johndevs/gradle-vaadin-plugin
It will help you with Vaadin-specific task like building widgetsets, creating components skeletons, etc.
I think there is no a Vaadin plugin for Gradle but I have used Gradle in one of my Vaadin add-on projects: SplitButton. It's a project with sub-projects, widgetset compilation and it writes necessary jar manifest entries neebed by Vaadin Directory.
EDIT
Actually there is Gradle Vaadin plugin now - it allows you to easily build Vaadin projects with Gradle. It helps with the most tedious tasks when building a Vaadin project like building the widgetset and running development mode. It also helps you to quickly get started by providing tasks for project, component and theme creation:
https://github.com/johndevs/gradle-vaadin-plugin
You don't need a Vaadin plugin. A Vaadin application is simply a web application.The war plugin will suffice. If you want support for automatically creating the folder layout that Vaadin wants however, you might look into using the vaadin eclipse plugin found here:
http://vaadin.com/eclipse
If you are looking for deployment support, you can simply use the jetty plugin that comes with gradle or the tomcat plugin found here
https://github.com/bmuschko/gradle-tomcat-plugin
If you need to create custom widgets and compile them into a widgetset that's a GWT compile
https://vaadin.com/book/vaadin6/-/page/gwt.development.html#gwt.development.compiler
Note: The Vaadin7 Book no longer has the section on developing Gwt widgets.
There is a gradle plugin for GWT that could help with that. However, I've not needed a custom widget yet, so I haven't actually tried it.
https://github.com/markuskobler/gwt-gradle-plugin
This post:
Using Gradle with Vaadin
looks very comprehensive as far as Gradle+Vaadin setup goes. I'm also including a link to another Vaadin-based 'build.gradle' file I found on my travels, using Google's very useful 'filetype' search (see also the associated gradle.properties file).
JFYI that Google file search is:
filetype:<extension> <your search phrases>
Gradle can also be used to configure Eclipse and IntelliJ's project files by using a fragment such as the following (Eclipse natures can be 'found' by using the above Google file search for "project" extension and "natures" search, etc.):
//Template plugin - Great for project-layout setup - See http://tellurianring.com/wiki/gradle/templates
apply from: 'http://launchpad.net/gradle-templates/trunk/latest/+download/apply.groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
// if you want to distribute the gradle with your code
task('wrapper', type: Wrapper).configure {
gradleVersion = '1.0-milestone-8a'
}
def versionCompatibility = 1.6
//configurations.providedDependencies.extendsFrom configurations.gwt
eclipse {
project {
comment = ""
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "org.eclipse.wst.jsdt.core.javascriptValidator"
buildCommand "org.eclipse.wst.common.project.facet.core.builder"
buildCommand "org.eclipse.wst.validation.validationbuilder"
buildCommand "com.vaadin.integration.eclipse.widgetsetBuilder"
//buildCommand "org.eclipse.m2e.core.maven2Builder"
//buildCommand "org.maven.ide.eclipse.maven2Builder"
//buildCommand "com.google.gdt.eclipse.core.webAppProjectValidator"
//buildCommand "com.google.gwt.eclipse.core.gwtProjectValidator"
//buildCommand "com.google.gdt.eclipse.designer.GWTBuilder"
//Don't forget commas - no trailing
natures "org.eclipse.jdt.core.javanature",
"com.vaadin.integration.eclipse.widgetsetNature",
"org.eclipse.wst.jsdt.core.jsNature",
"org.eclipse.wst.common.project.facet.core.nature",
"org.eclipse.wst.common.modulecore.ModuleCoreNature",
"org.eclipse.jem.workbench.JavaEMFNature"
//"org.eclipse.m2e.core.maven2Nature",
//"org.maven.ide.eclipse.maven2Nature",
//"com.google.gwt.eclipse.core.gwtNature"
//"com.google.gdt.eclipse.designer.GWTNature",
//"ch.epfl.lamp.sdt.core.scalanature",
//"com.springsource.sts.grails.core.nature",
//"org.eclipse.jdt.groovy.core.groovyNature"
}
classpath {
containers "com.google.gwt.eclipse.core.GWT_CONTAINER"
//"com.springsource.sts.gradle.classpathcontainer"
//minusConfigurations=[configurations.gwt]
}
}
idea {
project {
jdkName = versionCompatibility
ipr {
withXml { provider ->
def node = provider.asNode()
// Set Gradle home
def gradleSettings = node.appendNode('component', [name: 'GradleSettings'])
gradleSettings.appendNode('option', [name: 'SDK_HOME', value: gradle.gradleHomeDir])
}
}
}
}
Cheers
Rich

How to get grails plugin version from app?

How to get grails plugin version from app?
Details: my app is also a grails plugin.
When I set version, using
grails set-version 0.5
I can't get value using grailsApplication.metadata['app.version']
because value is updated in my FooBarGrailsPlugin.groovy class
The application.properties file remains unchanged.
Tks.
When I run set-version, my class change from:
class FooBarGrailsPlugin {
def version = 0.1
}
to
class FooBarGrailsPlugin {
def version = 0.5
}
The following code will print out the name and version of all plugins installed in an app
applicationContext.getBean('pluginManager').allPlugins.each {plugin ->
println "${plugin.name} - ${plugin.version}"
}

Resources