Grails war produces JAR file in version 3.1 - grails

We're using Grails 3.1 and I'm trying to build a WAR to be run on an external Tomcat container, but when I run grails war, it creates a JAR file in the <project_dir>\build\libs directory. How do I configure Grails to produce a WAR file?

Grails 3.1.2 was released earlier today and includes a bug fix for your issue: https://github.com/grails/grails-core/issues/9736.

Upgrading to 3.1.2 didn't solve the problem. I'm using the web-api profile, so I'm not sure if things are different from the default profile.
However, I did solve this by applying the Gradle war plugin in build.gradle. Note: originally I had the war plugin last, after the other Grails plugins; and it did not work. It worked fine after moving it before them.
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.plugins.views-json"

Grails 3 is using gradle.
gradle war
And make sure you are using Tomcat 8 and above. For tomcat 7 you need to remove internal tomcat8 jars from war in the config file.

Related

Equivalent to maven-install command in Grails 3

I have begun the journey of migrating my Grails apps to version 3.
I have a number of plugins that I with Grails 2 have installed to the local maven repository with the maven-install command available with the release plugin. They have then been easily accessible to my main project for import.
As far as I can see the release plugin does not exist for Grails 3. My question is, should I try to migrate the release plugin or is there some other, better way, in Grails 3?
If you have
apply plugin: 'maven-publish'
and the two apply from: 'https://raw.githubusercontent.com/... lines from the build.gradle file that's created for you when you create a Grails 3 plugin you can run
./gradlew install
to do the same thing as the maven-install script.

Grails Standalone Plugin Not Found

I'm trying to use the grails standalone plugin with a new grails project but I can't get it to work.
I've added it as a plugin dependency in my BuildConfig.groovy file:
plugins {
compile: ":standalone:1.2.3"
}
But I get the following error when I attempt to run grails prod build-standalone:
Script 'BuildStandalone' not found, did you mean:
1) InstallDependency
2) Stats
3) InstallJQuery
4) CreateMultiProjectBuild_
5) TestApp
I tried running grails clean, grails clean-all, grails refresh-dependencies, and grails compile as answered in this question, but nothing seems to help. I would expect refresh-dependencies to either download the necessary artifacts or fail trying.
What am I doing wrong?
Here is my environment:
Mac OS X 10.9.5
JDK 1.8.0_05
Grails v2.4.4 installed with GVM
Always run grails compile after editing dependencies in BuildConfig.groovy; this triggers dependency resolution and installs the plugin, downloads the jars and adds them to the classpath etc. Once that happens the plugins' scripts will resolve.

How do I know what webserver gradle / grails is using?

This thread: Gradle / Grails application describes how to set up the grails plugin for gradle.
The command gradle grails-run-app tries to start the grails application on port 8080. What webserver is gradle using here?
Does it have an embedded one? If so how can I access / configure it?
It just shelling out to the same thing that Grails would have done without Gradle, as if you had run grails run-app. That depends on which server plugin you have installed. By default it's http://grails.org/plugin/tomcat, but you can switch to http://grails.org/plugin/jetty by changing the values in grails-app/conf/BuildConfig.groovy
Gradle is nothing but a build and config tool like maven. When you use it with Grails app the dependencies are managed by it as it happens when maven is used.
When you use gradle grails-run-app it does nothing more other than running grails run-app from its own context. The same embedded Tomcat server is used by default.

How to run a local plugin in Grails 2.0?

In Grails, there is a variant how to include local plugin from sources. According to docs, one may type in BuildConfig.groovy:
// Useful to test plugins you are developing.
grails.plugin.location.shiro =
"/home/dilbert/dev/plugins/grails-shiro"
// Useful for modular applications where all plugins and
// applications are in the same directory.
grails.plugin.location.'grails-ui' = "../grails-grails-ui"
The problem is that it doesn't work in Grails 2.0.RC1. I've tried to do grails clean, to install plugin with grails install-plugin and to place it to BuildConfig.groovy. Still unable to resolve.
This works for me
grails.plugin.location.shiro = "/home/dilbert/dev/plugins/grails-shiro"
Where shiro is the name of the plugin (not the name of the directory it's in). Make sure the path to the plugin is either an absolute path or the relative path to the plugin from the application.
I've found that this sometimes doesn't work if the plugin is listed in application.properties or BuildConfig.groovy, so if it is, remove it, then execute grails clean and restart the app.
You can also install the plugin into your local maven cache.
The documentation speaks about this:
3.7.10 Deploying to a Maven Repository
maven-install
The maven-install command will install the Grails project or plugin artifact into your local Maven cache:
grails maven-install
This has the advantage of allowing you to include the plugin in your parent application using the more common ":plugin-name:version" syntax
Which allows your application to determine the best place to retrieve the plugin when in production. From an internal maven-repo or equivalent.
With Grails 3.x there is another way to do this. Suppose you've a grails app and plugin (source code) inside the same project directory:
/my-project
---/my-app
---/grails-shiro
To run your local plugin, you must create a settings.gradle file in the my-projectdirectory specifying the location of your application and plugin:
include 'my-app', 'grails-shiro'
Then add the dependency in your application's build.gradle:
compile project(':grails-shiro')
You've done.
Look at the plugins documentation for more information.
Surround the plugin name with quotes in case it contains dashes:
grails.plugin.location.'plugin-name-with-dashes' = "<path>"
You can add the .zip file for the plugin in your /lib and it will be installed.
Example:
compile ":myPlugin:1.0"
File:
/lib/myPlugin-1.0.zip
Note: You have to zip the content of the plugin folder.
Source: http://grails.1312388.n4.nabble.com/Insert-own-local-plugin-into-build-config-td4646704.html

How to build from my checkout directory ... with a twist

We're using Maven 3 with Git as our SCM system. We are using the latest version of the scm plugin (1.5). Our project is in Grails 1.2.1 (Java 1.5). The question is, how do I run a single command to generate a WAR file after doing a checkout from our repo?
This question seems complicated by the fact that we're using the a Grails project (and hence the maven-grails plugin, version 1.3.4). Grateful for any info you have, - Dave
I'm assuming that the command line below below wont work for you because of your requirement to use maven.
grails <environment> war
You can generate a pom.xml for your existing grails project with the following command. This can be a useful starting point.
mvn grails:create-pom
More documentation about grails's maven integration can be found here:
http://grails.org/doc/latest/guide/4.%20The%20Command%20Line.html#4.5%20Ant%20and%20Maven

Resources