Why grails run-app tries to access remote servers during compiling - grails

I found there are some errors during my grails application compiling.
| Loading Grails 2.0.4
| Configuring classpath
:: problems summary ::
:::: ERRORS
Server access Error: Unexpected end of file from server
url=http://plugins.grails.org/grails-shiro/tags/RELEASE_1_2_0-SNAPSHOT/shiro-1.2.0-SNAPSHOT.pom
But I can access the above url using my browser. What does the error mean? and is there any way to avoid such problems during compiling? Or can I compile my grails app locally?
when I need some grails plugin, I usually run
grails install-plugin xxx
to install xxx plugins. I noticed that there are some records automatically written in 'application.properties'. And the plugins are always installed in my ~/.grails//projects/plugins/, I am wondering whether there are ways to compile grails app locally?

You have a SNAPSHOT plugin, that means that Grails have to refresh this plugin periodically (once a day).
To disable remote repositories you can use --offline to work offline:
grails --offline run-app
Or disable it completelly by adding into BuildConfig.groovy:
grails.offline.mode=true
See docs for Dependecy Resoultion - https://grails.github.io/grails2-doc/2.0.4/guide/conf.html#dependencyRepositories
P.S. Latest stable version of Shiro plugin is 1.1.4, you could also use it instead of 1.2.0-SNAPSHOT. Stable version will be downloaded only once.

Related

Upgrading a plugin fails going from Grails 3.1.11 to 3.2.2

I'm working on a Grails plugin whose main contribution is a taglib. In Grails 3.1.11 it worked ok. I also have a simple Grails app just for testing the plugin. Enter Grails 3.2.2.
After migrating plugin and app to 3.2.2 the plugin shows no signs of life. The plugin doWithApplicationContext closure is no longer executed at app startup. The taglib is not found by gsp:s. I did the migration by creating a new plugin and app with Grails 3.2.2 and then fill in the sources.
Sorry for this vague question, but what strings should I pull to find out what's wrong?
Edit 1: Yes, I did the sanity check to have the app depend on a non-existing version of the plugin and got the expected conflict. So it's not that the plugin is totally decoupled from the app.
Edit 2: After setting DEBUG logging on packages grails.plugins and org.grails.plugins a warning message appeared. It came from org.grails.plugins.CorePluginFinder. It couldn't find the plugin descriptor (...Plugin.groovy). I examined the plugin jar, found the plugin descriptor class in a file hierarchy rooted in BOOT-INF. Clearly the plugin loader didn't look into that hierarchy. I thought I was seeing a Grails bug because I didn't know about Boot repackaging. I added a post here to that effect, but after getting Graeme's answer I deleted the post because it detracted attention.
What you are seeing is that if you run gradle assemble on a plugin then the bootRepackage task is run which re-packages the plugin JAR as a runnable JAR which is not what you want when you plan to use the plugin from an application.
If you simply run gradle publish or gradle publishToMavenLocal or gradle jar then you get the JAR file that has not been re-packaged by Boot. As far as I am aware this is not a change from Grails 3.1.
You can also disable Boot repackaging all together in the plugin build.gradle if you never plan to use the plugin as an actual application or runnable JAR file:
bootRepackage.enabled = false

Resolving view from webflow when running app with run-web

I have grails app that uses plugins to modularize app. Structure of app is as follows:
pluginA
pluginB
pluginMain
On one of those plugins (say pluginA) I have controller that uses Spring Webflow (using Spring Webflow 2.0.8.1).
Plugins are resolved locally in BuildConfig.groovy of pluginMain (grails.plugin.location.'pluginA' = "../pluginA"
grails.plugin.location.'pluginB' = "../pluginB").
When running app with run-app views used by webflow are resloved OK.
But, when I run app with run-war controller from pluginA tries to resolve view from location pluginMain/WEB-INF/grails-app/views/controllerName/flowName/nameOfView.jsp instead from pluginA
so I am getting HTTP 404 not found error.
I am using grails 2.3.7 and java jdk 1.7.
Please help!
The location that it is looking for in the run-war situation is the standard location for resolving page and flow views. You are likely getting into trouble by attempting to create a war file using inline plugins (the grails.plugin.location).
The inline plugin support is really nice when developing plugin functionality, but it has its quirks, particularly when you get multiple dependent plugins in play. At some point you have to break down and start publishing your plugins.
Try publishing the plugin to your local Maven repository using the "maven-install" command. Then change your BuildConfig.groovy file to reference the installed version of the plugin.
My normal workflow is something like this:
Develop the new plugin functionality using an inline plugin definition in BuildConfig.groovy, testing with run-app and run-test until I'm happy.
Publish a SNAPSHOT version of the plugin (ie. 1.0.1-SNAPSHOT) and update BuildConfig.groovy to point to the snapshot and test using run-app and run-war eg:
compile (":ark-kpi:1.0.1-SNAPSHOT")
Publish your plugin in release form either to your local maven repository (maven-install) or a public repository like a locally running Artifactory if you want to share with colleagues (publish-plugin).
You should read the guide section on plugins and configuration for details on setting up repositories.

Error installing Grails plugin to local maven repository

I have created a Grails plugin using Grails 2.3.3 and trying to use the plugin in a Grails application which was also created using Grails 2.3.3. Now, to use the plugin in the application, it needs to be published to a plugin repository first. So I attempted to publish the plugin into the local repository by using the commands:
grails clean
grails compile
grails maven-install
For the grails maven-install command I selected the option 2)InstallPlugin. But then got an error:
Error installing plugin: No such property: ERROR_MESSAGE for class: Inst
allPlugin (Use --stacktrace to see the full trace)
Ran the last command above with option --stacktrace and --verbose but did not get any clue as to what the problem might be. I also removed %HOME%/.grails directory and reran the above commands and still came with the same error.
After googling, I found a JIRA for this issue which was closed stating that it happens when Grails version is changed and cleaning up cache files will get rid of this issue. However, that solution is not working for me and, by now, I have spent couple of hours trying to fix this. Also I did not change my Grails version.
Has anyone faced this issue with Grails 2.3.3 or with any recent version of Grails? What was the solution?
Don't use install-plugin, add a dependency in BuildConfig.groovy.
I don't know where the 2)InstallPlugin "option" is coming from. The maven-install script packages your plugin and generates a POM file and the other files needed to be a valid published plugins. Then it copies these files to your local M2 directory, e.g. if your plugin name is "mycoolplugin" the files are copied to $HOME/.m2/repository/org/grails/plugins/mycoolplugin
Now you can "install" the plugin as if it had been published in a remote repo. Add a dependency in the app's BuildConfig.groovy using the usual format, e.g.
plugins {
build ":tomcat:7.0.50"
compile ":scaffolding:2.0.1"
runtime ":hibernate:3.6.10.7"
...
compile ":mycoolplugin:0.1"
}

How to resolve external dependencies defined in a Grails plugin in a Grails 2.2.x application

I asked this question on the Grails user list but didn’t get a response, so I’ll rephrase it here. I’m the author of a Grails plugin (https://github.com/kensiprell/grails-atmosphere-meteor), which has two external dependencies defined in BuildConfig.groovy.
When the plugin is installed in a new Grails 2.2.x application, the external dependencies are not resolved in the app. When running it I get "unable to resolve class" errors on the import statements for the classes defined in the plugin’s dependencies.
A plugin user should be able to insert the plugin dependency in an app’s BuildConfig.groovy and have the two external dependencies resolved automatically. grails.project.dependency.resolution.legacyResolve should be the default value of false.
Additionally, I want to test the plugin using https://github.com/kensiprell/grails-plugin-test-script before publishing it to the Grails plugin portal. I have an artifactory repo running on localhost (defined as localPluginReleases in the plugin's BuildConfig.groovy).
The plugin is built using Grails 2.2.3 and uses release plugin version 2.2.1. I've tried varying combinations of the below without success:
grails clean
grails compile
grails maven-install
grails generate-pom
grails package-plugin
grails publish-plugin --noScm --repository=localPluginReleases
grails maven-deploy --repository=localPluginReleases
What is the correct step-by-step to get this working?

Grails always tries to uninstall plugin

Each time I'm runnin Grails app, it tries to uninstall an plugin (resources-1.2.RC2). When it installed using IntelliJ IDEA, it uninstall it sucessfully, I see:
| Uninstalled plugin [resources]
and fails with:
| Error Fatal error during compilation org.apache.tools.ant.BuildException:
srcdir "***/2.1.1/projects/***/plugins/resources-1.2.RC2/grails-app/resourceMappers"
does not exist! (Use --stacktrace to see the full trace)
Notice, that I can install this plugin only by using InteliJ IDEA, when I'm trying to install it from command line (using grails install-plugin resources) it logs only:
| Plugin not installed.
If plugin isn't installed, and i'm doing grails run-app, it writes (each time!):
| Warning No plugin [resources-1.2.RC2] installed, cannot uninstall
app fails because cannot find required classes from resources plugin.
--
I guess it's happening because of corrupted config inside ~/grails (I've tried to uninstall it some time ago), and it execute this action on each run. But I can find.
I even tried to remove project dir from ~/.grails/2.1.1/projects - not helped.
How I can stop it from removing this plugin? Whre grails stores infomration what plugin it shoud uninstall?
PS Also, I can't understand, why plugins { compile ":resources:1.2.RC2" } in BuildConfig.groovy not used by grails? I always need to run install-plugin command to make it working?
Actually, install-plugin is deprecated. Use BuildConfig.groovy instead. To get everything set up properly, delete all plugins from your application.properties file. Then add them to your BuildConfig.groovy.
IntelliJ is not really good with catching these kind of updates, so you might have to run refresh-dependencies manually after updating your BuildConfig. That is properly why it didn't work before.

Resources