How to change Grails 3 SDK path in IntelliJ project once created? - grails

I would like to change my project from Grails from 3.0.9 to 3.0.10 since latter contains Promise API.
How to do that in IntelliJ?

in the gradle.properties file change
grailsVersion=3.0.10
also in the build.gradle change
buildscript {
ext {
grailsVersion = project.grailsVersion
}
}

You just need to change the grails version in gradle.properties. The gradle build script will pull the required jar files from the grails repo specified in your build file.

Related

Grails 3 set-version replacement

On our Grails 2 projects we used the set-version command line option. I do not see that command available in Grails 3. I do see the version property in the gradle.build file. Did that replace the app.version from the application.properties? I build our projects using Jenkins and SVN repository. What is the best way to handle setting the version parameter for Grails 3 to the SVN revision number. Below is a section of the build.gradle file, that includes the version property, which is generated when creating a Grail 3 application.
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
classpath "org.grails.plugins:hibernate5:6.0.0.M2"
}
}
version "0.1"
group "appName"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
In grails 2 the property was called app.version (from the application.properties file) and could be referenced in gsp using the following:
Revision: <g:meta name="app.version"/>
After some trail and error using Grails 3.2.0.M2 I was successful using the Gradle plugin to Jenkins. I was able to use the Environment variable SVN_REPOSITORY so I edited the build.gradle to:
version System.getenv('SVN_REVISION')
Also I noticed in the generated index.gsp that the property name for the version value using the g:meta tag library has changed. The name has changed to info.app.version so here is an example how to use the value now:
<g:meta name="info.app.version"/>
Also for the grails version the name has also changed:
<g:meta name="info.app.grailsVersion"/>

how grails 3.0.x create custom war name with different file suffix

In grails 3.0.(1,2,3) the war file exist under the folder 'build/libs'
However, I want to rename the war name with different file suffix, like "app.tar.gz", without the version.
the google result is all about grails 2.x
I put the grails.project.war.file = "target/${appName}.tar.gz" in the file application.groovy under the folder conf but it's useless.
Plz help me, i googled and try to find solution in the source code BuildSettings.groovy, but the it's no use.
As of grails version 3, the build tool is gradle, you would need to change those parameters from your build.gradle file
If you do not want the version as part of your package name, you will need to comment (or remove) the version from build.gradle file
for example, running the following
fhenri#machine:~/project/grails/sample307$ grails -version
| Grails Version: 3.0.7
| Groovy Version: 2.4.4
| JVM Version: 1.8.0_51
fhenri#machine:~/project/grails/sample307$ grails package
...
fhenri#machine:~/project/grails/sample307$ find . -name *.war
./build/libs/sample-0.1.war
After you remove the version from `build.gradle` file
fhenri#machine:~/project/grails/sample307$ grails package
...
fhenri#machine:~/project/grails/sample307$ find . -name *.war
./build/libs/sample.war
Grails uses the war gradle plugin, from the plugin the pattern to make the archive name is [baseName]-[appendix]-[version]-[classifier].[extension], the version already comes from the build.gradle file as generated from grails create-app
each of this can be overwritten in a war closure, for example, an excerpt of the build.gradle could be
version "0.1"
war {
appendix "so-test"
version "1.0"
}
The generated war file will be sample-so-test-1.0.war the version will come from the war closure.
So if you want to keep the mail version properties but do not want to generate the version in your generated war name you can overwritten the property with an empty value
version "0.1"
war {
version ""
}
will generate a war file without the version information, but still you could keep it for you if you want to use it somewhere else.
To package as tar/zip, you can
follow the documentation for grails 3: http://grails.github.io/grails-doc/latest/guide/deployment.html (chapter on TAR/ZIP distribution)
In build.gradle, after applying the gradle war plugin you can do this:
war {
archiveName = "ROOT.war"
}
And a ROOT.war file will be created at build/libs

How to use grails.plugin.location?

I have a plugin project which I created as grails create-plugin myPlugin. I also created a 'normal' grails project as grails create-app myPluginDemo. I'm trying to install myPlugin plugin in myPluginDemo but don't understand how to use grails.plugin.location.
Where do I put grails.plugin.location inside BuildConfig.groovy? Inside plugins section? Inside repositories section?
What should I append to grails.plugin.location? Should it be grails.plugin.location.myPlugin? Or grails.plugin.location.grails-my-plugin? Something else?
grails.plugin.location is not a dependency resolution, so it goes outside grails.project.dependency.resolution.
It should be like below, if both myPluginDemo and myPlugin are in the same directory. Moreover, this will not install the plugin into the app, but the application will refer to the file system for the plugin which is convenient in development mode. In order to use the packaged plugin it has to be referred in plugins inside grails.project.dependency.resolution
grails.plugin.location.myPlugin = "../myPlugin"
grails.project.dependency.resolution = {
repositories {
}
dependencies {
}
plugins {
}
}

How can I include a dependant jar in a multi project grails / gradle build?

I have the following setup within my project...
A multi project gradle build for a SOA style project, wired together using rabbitmq and spring integration.
Contains a number of grails projects as well as plain java / groovy projects to represent the services.
Alongside each of the service projects are a project (jar) containing all of the public interfaces (and messages) for the service that can be proxied using spring integration.
The projects are related to each other using gradle dependencies and then I generate IntelliJ projects files using the gradle idea plugin.
What I want to do is:
Include the interfaces jar in the grails project so that I can use spring integration there to proxy my calls into the services via rabbitmq.
When I run the grails app have this intefaces jar built and included within grails.
When I run the grails app from IntelliJ have it compile the latest version of the interfaces and include them in the grails project.
When I build the entire project from gradle, have gradle correctly associate the interfaces jar with the grails app.
Ideally I would love to be able to do this just using dependency declaration within gradle, but this is probably a pipe dream...
What are my options?
Add a task into the grails build lifecycle within gradle to build any dependant jars and copy them into the grails lib folder?
Hook into the grails build lifecycle by using Events.groovy or similar to call out to grails to build and package the dependant jars. This would cover both the IntelliJ and command line routes.
Build the interfaces as a grails plugin? I had discounted this as they also need to be used from non-grails projects.
Any help / advice would be appreciated.
Turns out all I needed to do was add the following and then the grails plugin deals with the dependencies for me...
compile project(':dependent-project')
Works nicely for run-app and war...
A partial solution to the problem would be to use both Gradle and Grails maven plug-ins. I have a similar situation where I am building jars that are dependencies of the Grails project.
The approach I've chosen is to install the java artifacts into the local .m2/repo and then declare the dependency under grails/conf/BuildConfig.groovy using the mavenLocal() repo.
What I hadn't considered was to hook gradle into the events lifecycle (interesting idea, btw) and instead defined a gradle project that wraps the grails app (executes test-app, run-app, etc). The gradle wrapper for my grails app has a dependency on the other component's install task so it always checks to see if it needs to be rebuilt.
I'm an Eclipse user so I can't comment on the Intellij part of your question but the above works for me so I hope it gives you some ideas?
My solution for the moment is to:
Use the grails / gradle plugin to build the grails projects.
Use this plugin to run my grails apps, ie. gradle grails-run-app.
Hook into the grails-run-app task in gradle (which is created on the fly) to call a task which builds and copies the dependencies into the lib directory.
This doesn't help a whole load with IntelliJ at the moment but I will run my gradle tasks as IntelliJ run configurations.
My build.gradle is as follows (dependent-project is being jarred and put in lib in this example):
import org.grails.gradle.plugin.GrailsTask
evaluationDependsOn(':dependent-project')
buildscript {
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
dependencies {
classpath "org.grails:grails-gradle-plugin:1.1.1-SNAPSHOT"
}
}
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
ext {
version = "1.0"
grailsVersion = "2.2.0.RC2"
grailsTaskPrefix = "grails-"
}
apply plugin: "grails"
dependencies {
['dependencies', 'resources', 'core', 'test', 'hibernate', 'plugin-datasource', 'plugin-domain-class', 'plugin-tomcat', 'plugin-services'].each { plugin ->
compile "org.grails:grails-$plugin:2.2.0.RC2"
}
bootstrap "org.codehaus.groovy:groovy-all:2.0.5"
}
// Get hold of the grails-run-app task (which is created on the fly) and add a dependency to the copyDependencies task
project.gradle.afterProject { p, ex ->
if (p == project) {
project.tasks.addRule("Grails dependencies") { String name ->
if (name.startsWith(grailsTaskPrefix)) {
tasks.getByName(name).dependsOn(copyDependencies)
}
}
}
}
// Build and copy any dependent jar files...
task copyDependencies(type: Sync) {
from project(':dependent-project').configurations.archives.allArtifacts.files
into "$projectDir/lib"
}

grails plugin DSL specify zip file

When using the grails plugin dsl in BuildConfig.groovy, such as
plugins {
build "org.grails.plugins:db-util:0.4"
}
Is there a way to specify to use a plugin from a zip file like you can do with grails install-plugin?
Not directly, but of you put the zip file in a directory and name it without the grails- prefix, then declare that directory as a flatDir repository then Grails will be able to resolve the plugin from there.
repositories {
flatDir name:'localPlugins', dirs:'../local-plugins'
}
// copy plugin zip to ../local-plugins/my-plugin-1.2.zip
plugins {
compile ':my-plugin:1.2'
}
Or if it's a locally built plugin you could install it into your local maven cache using grails maven-install and just use mavenLocal() instead of the flatDir.

Resources