Disable Minifying in Gradle - grails

How to disable minifying of .css and .js in my gradle configuration?
OBS: Grails v.2.4.0, Gradle v.1.12 and asset-pipeline v.1.8.7
I have been trying some of the following options:
In Config.groovy
grails.assets.minifyJs = false
grails.assets.minifyCss = false
// as well as some others, but without success
Commenting pipeline-plugin in dependencies.gradle
Commenting assetCompiler.compile() in _AssetCompiler.groovy
What I expect to achieve by doing this is less build time for local deploys and make a new Task for generating a new .war without minifying while still having the old 'war' option for a complete production build.

Run grails clean-all command. It cleared the issue for me after upgrading to asset-pipeline
Ref: Reverse case for these guys: Grails assets not minified

Related

Does the Grails "war" command minify JavaScript files?

I have a Grails application building in an AWS CodePipeline. We recently upgraded from Grails 4 to Grails 5 and now one of the third-party JavaScript packages we use is having a problem because it's being minified somewhere in the build process, but the minification process is not properly renaming a particular variable in all parts of the js file. I'd like to switch the minify option in our build process to whitespace only in order to prevent the js variable names from being renamed/shortened. In my local builds, I use the asset-pipeline plugin in build.gradle to minify the js files and I set the optimization level to whitespace only...which works great...but I'm not sure where/how to do that in the AWS CodePipeline.
In the buildspec.yml file being used in the codepipeline, we are simply installing Grails 5 and then issuing the following command: /root/.sdkman/candidates/grails/current/bin/grails war -Dgrails.env=$GRAILS_ENVIRONMENT
Someone on the team thought the Grails war command might be responsible for the js minification, but I haven't been able to find anything. Hence my question here. Any help would be appreciated.
I figured it out. The minification does occur during the WAR creation. I had to add the following code to the application.groovy file in order to minify whitespace only.
grails.assets.minifyOptions = [
optimizationLevel: 'WHITESPACE_ONLY' //SIMPLE, ADVANCED or WHITESPACE_ONLY
]
I also had to modify the problematic js file by adding a comment to it in order to force that file to be re-compiled.
https://bertramdev.github.io/grails-asset-pipeline/guide/usage.html

Grails plugin which one is good closure-compiler or uglify-js-minified-resources

I am using uglify-js-minified-resources plugin to minify the files. But it always minify the files before serving means files minify per request. Is there any setting for it that it minify the files on application startup. Also want to know if closure-compiler is good enought for it.
The YUI War Minify plugin will minify resources at War creation time. This should do what you are looking for.

How to deploy grails app with private plugin to cloud

I've created a private plugin for domain objects that are shared between two grails applications. I'm able to use the plugin successfully in my local environment as I've set the path to it via the BuildConfig file. For example, I have the following directories:
appOne/
myPlugin/grails-my-plugin-0.1.zip (myPlugin is a grails plugin project dir)
In: appOne/grails-app/conf/BuildConfig.groovy:
grails.plugin.location.compileMyPlugin = "../myPlugin"
My question is, what is the proper/best way to handle "packaging" this plugin with my app release so I can deploy it to a cloud service where it won't be available for download? I imagine there is a way to have grails do this for you but I'm unsure. (I'm very new to grails)
When you create you .war file for deployment, grails simply includes your plugin. So you have nothing special to do.
If your project is build in the cloud, you might try to specify a file path as local repository:
repositories {
grailsCentral()
localRepo "../myPlugin"
}
Just drop your zipped plugin in this folder and grails will find it.
I ended up doing the following to resolve this in Grails 2.1.0:
1) In the Grails Plugin Project:
grails package-plugin Produces the grails-myplugin-0.1.zip file
2) Copy plugin to my application's lib directory (appOne/lib/grails-myplugin-0.1.zip)
3) In BuildConfig.groovy
Remove: grails.plugin.location.compilemyPlugin = "../myPlugin"
This was/is used during development to prevent the rebuild-reinstall process
when updating files included in the plugin.
Add:
plugins {..... compile ':grails-myPlugin:0.1' }
4) Test by cleaning appOne and re-run which will install/re-install the plugin via the lib directory
5) Commit all changes and add the plugin zip file to appOne and push. The cloud provider,
Heroku in this case, can then resolve the dependency.
Your build script should first package the plugin, then install the plugin into your Grails application. At least, that is how I have to do it. If you try and have both your plugin specified in the BuildConfig dependencies and as an inline plugin, Grails tends to complain about that.

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

Grails Inline Plugins: Cannot Upgrade a plugin that is configured via BuildConfig.groovy

Our app is split into a main application and a few plugins. We're using inline plugins via the BuildConfig.groovy file. When it is time to WAR the whole thing up for production I'm getting the following message:
You cannot upgrade a plugin that is
configured via BuildConfig.groovy,
remove the configuration to continue.
And then Grails wants to uninstall the plugin because it can't find it in application.properties. But during development, having it in application.properties causes issues. So when we're ready to create a production WAR, how do we work around this without commenting the plugins in BuildConfig.groovy every time?
BuildConfig.groovy is read rather early in the run process, so not all of environment data is yet available. However, it is interpreted as a regular groovy script, so you could try taking advantage of the fact that the war task is run in production environment:
// BuildConfig.groovy
if (System.getProperty("grails.env") == "development") {
// specify the inplace plugin normally here
}

Resources