Saturday, August 10, 2013
Friday, July 26, 2013
Review of the Grails Gradle Plugin
UPDATE: Using the bootstrap configuration for the Tomcat plugin excludes it from the grails-war task.
See https://github.com/grails/grails-gradle-plugin/pull/43
Gradle support for Grails is maturing slowly and I must say that I can't wait for Grails 3.0. "Oh yeah, I'm excited!" :-), almost.
There are still few bits that I'm not clear about though in terms of how tight the integration will be, not specifically from an IDE usage perspective.
I watched a presentation from Luke Daley (aka alkemist) on Youtube(gr8conf 2013). It showcased the Gradle plugin for building Grails applications using the grails-gradle-plugin.
I was able to create a small POC and I want to share that experience with you.
General notes
Building a war and running Grails commands? Not a problem.gradle grails-run-app
gradle grails-war
You can configure the Grails environment using -PgrailsEnv as
-Dgrails.env=
Arguments can be specified using -PgrailsArgs
gradle -PgrailsArgs='com.Domain' grails-create-domain-class
For some reason, the grails-gradle-plugin seems to require a closure with a Grails version specified twice (assuming that version is only used for bootstrapping the initial call??, while grailsVersion is used for building). I think that it should probably be consolidated...
grails {
grailsVersion '2.2.3'
version '2.2.3'
}
Below is a build.gradle file that does work for the Grails Gradle plugin 2.0.0-SNAPSHOT. Dump the file into some folder and run gradle init first.
buildscript {
repositories {
mavenCentral()
maven { url 'http://repository.jboss.org/maven2/' }
maven { url 'http://repo.grails.org/grails/repo' }
maven { url 'http://repo.grails.org/grails/plugins' }
maven { url 'http://repository.springsource.com/maven/bundles/release' }
maven { url 'http://repository.springsource.com/maven/bundles/external' }
maven { url 'http://repository.springsource.com/maven/libraries/release' }
maven { url 'http://repository.springsource.com/maven/libraries/external' }
}
dependencies {
classpath 'org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT',
'org.grails:grails-bootstrap:2.2.3'
}
}
version='0.0.1'
apply plugin: 'grails'
repositories {
mavenCentral()
maven { url 'http://repository.jboss.org/maven2/' }
maven { url 'http://repo.grails.org/grails/repo' }
maven { url 'http://repo.grails.org/grails/plugins' }
maven { url 'http://repository.springsource.com/maven/bundles/release' }
maven { url 'http://repository.springsource.com/maven/bundles/external' }
maven { url 'http://repository.springsource.com/maven/libraries/release' }
maven { url 'http://repository.springsource.com/maven/libraries/external' }
}
grails {
grailsVersion '2.2.3'
version '2.2.3'
}
configurations {
all {
exclude module: 'commons-logging'
exclude module: 'xml-apis'
}
test {
exclude module: 'groovy-all'
}
compile {
exclude module: 'hibernate'
}
}
dependencies {
compile( "org.grails:grails-crud:$grails.grailsVersion",
'org.grails:grails-gorm:1.3.7')
bootstrap "org.grails:grails-plugin-tomcat:$grails.grailsVersion"
}
Sunday, June 30, 2013
About Java Software Installers and Launchers
1 Introduction
In the early stages of your software projects, it's a good practice to think about the distribution aspect. It doesn't matter how good a product is, if no one can perform the installation or run the application.
Generating software installers is not always easy, regardless of the installer product used.
If you're lucky enough to have a good commercial software installer, you can generate quickly packages without too much pain:
- Easy generation of application launchers.
- Good default settings with flexibility for splash screens, installer icons, pre-installation/post-installation actions, etc.
- Generation of software packages for a variety of platforms (OSX, Unix, Linux, Windows, etc.).
2 Application launchers
Now that your application development phase is complete, you may be worried about writing couple of launchers.
Writing a Java application launcher can become fairly complicated depending on :
- The amount of libraries dependencies used by the program.
- The configurations and properties to resolve or create in order to run the application properly.
- Any tasks that need to be executed prior to launching the application.
For Java based applications, below are the common steps performed by launchers scripts:
- Find the Java executable (
JAVA_HOME
detection if needed, common locations depending on the Operating System). - Validate the Java version requirements as well as potential optional settings.
- Setup any environment variables or system properties needed by the application.
- Construct the Java classpath from the application dependencies.
- Perform any actions need prior to launching the program.
- Invoke the Java command with the classpath and JVM arguments to start the application.
ClassWorlds is a simple Java application launcher framework that has been around for a while. It superseeded the forehead framework launcher. Forehead was used by many tools such as Maven (now using ClassWorlds).
What makes ClassWorlds compelling is that it's really easy to bootstrap an application launcher without much effort. All that Classworlds needs is a simple java command that references a boot jar file and your application configuration file(to load libraries).
3 Software Installers and packaging
Depending on the application's type, target audience and operating systems, many options are available. Commercial Software package generators usually provide good results without too much work. Decent to really good products for Java software packaging include InstallAnywhere and Install4j.
Some free Java-oriented installers generators can be found on java-source.net. A popular choice is IzPack.
Generating software packages by hand still gives you an overall better user's installation experience at the expense of time and potential bugs (typos, logic errors, etc.).
When your installation packages are ready, you then need to test them on all supported platforms, just to be safe.
Zip distributions are very convenient for many users:
- No administration rights needed most of the time, which is useful when you don't have administrative rights on a machine.
- One step installation, just a matter of extracting a software archive.
- Easy uninstallation which is a simple folder deletion.
When generating software packages, don't forget the simple way of distributing files via zip archives.