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"/>
Related
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.
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.
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
I'm trying to convert a Grails 2 plugin to Grails 3 and I have trouble excluding a couple of domain classes that are used in tests only from the resulting jar.
The documentation states:
in your build.gradle you should exclude the compiled classes from the JAR file:
jar {
exclude "com/demo/**/**"
}
...but if I try this I get the following error from Gradle:
Could not find method jar() for arguments [build_64zizslf5a7zfo329yz5tdsoi$_run_closure1#566c53c] on root project '...'
I can post the entire stack trace but it doesn't look very helpful. I'm using Gradle 2.3, provided by the default Gradle wrapper that the create-plugin command generates. I also haven't made any other changes to build.gradle because my plugin doesn't require any external dependencies.
See the project at https://github.com/jeffbrown/excludesdemo. That includes 2 domain classes under https://github.com/jeffbrown/excludesdemo/tree/master/grails-app/domain.
The top level build.gradle file at https://github.com/jeffbrown/excludesdemo/blob/72896a3f88f617d530bbdde8976d5bfe8d1e820a/build.gradle#L73 contains the following:
jar {
exclude 'package1/**'
}
When you run ./gradlew jar you should see that the jar file generated at build/libs/excludesdemo-0.1-SNAPSHOT.jar does contain package2/Author.class and does not contain package1/Person.class.
I'm trying to create Mavenized Grails application. Everything works fine but as I understood all the dependencies (all .jars like mysql-connector and also all grails (public) plugins like spring-security-core plugin) should be listed in pom.xml.
The thing is that I don't know how to include public grails plugins (is there any Maven repository for that, or should I include used plugins into my local repo?). Or is the proper way how to handle grails plugin to list them in "application.properties" and let the grails to manage these plugins?
Thank you for any comment.:-)
Mateo
You can specify your plugin dependencies in grails-app/conf/BuildConfig.groovy, for example:
grails.project.dependency.resolution = {
plugins {
runtime ':hibernate:1.2.1'
}
}
Update
In response to your comments below, a plugin dependency specified in BuildConfig.groovy (or application.properties) will still be resolved by Grails rather than Maven. I don't think there's any way that you can get Maven to resolve a Grails plugin dependency, because Maven can only work with JAR dependencies in Maven repositories. Remember, Grails plugins are not (typically) available from Maven repositories.
If you want to hand as much control as possible over to Maven, you can try excluding the JARs from your plugin dependencies, e.g.
plugins {
runtime( "org.grails.plugins:hibernate:1.2.1" ) {
excludes "javassist"
}
}
and add them to your pom.xml instead. Here be dragons (see below).
Editorializing
FWIW, unless you really have to build your Grails project with Maven (e.g. because another Maven project depends on it), my advice would be don't. I say this because Maven is very much a second-class citizen in the world of Grails build tools. The usual way to build a Grails app is using the built-in GAnt commands. Future versions of Grails will move towards Gradle as the default build tool, so it seems that Maven will be an afterthought for the forseeable future
By default, Grails plugins are included at the source level. A plugin zip is expanded, and the plugin source is compiled as part of the grails build process.
Since 2.0, grails can use binary plugins. You can depend on plain old JARS if those jars represent binary grails plugins.
Binary grails plugins can be referenced by normal maven coordinates.
Your project's BuildConfig.groovy is where you specify maven repositories and binary plugins.