How do I configure the version of Gradle to use with Grails 3.0? - grails

It seems like Grails 3 ships with Gradle 2.3 and I need to downgrade it to 2.2. Is there a way to tell grails to run gradle 2.2 instead of 2.3?

To set the gradle version that grails uses:
1) First, install your gradle version in a specific location. As I type this, gradle 2.9 goes with grails 3.1.4, but here are instructions for a gradle 2.2 installation, as you request.
a) wget -c http://services.gradle.org/distributions/gradle-2.2-all.zip
b) unzip gradle-2.2-all.zip
c) sudo mv gradle-2.2 /usr/local/gradle-2.2
d) set your GRADLE_HOME environment variable and add GRADLE_HOME/bin to the path. in your $HOME/.bash_profile or in a /etc/profile.d/gradle.sh file:
i) GRADLE_HOME=/usr/local/gradle-2.2
ii) export GRADLE_HOME=$GRADLE_HOME
iii) PATH=$PATH:$GRADLE_HOME/bin
iv) export PATH=$PATH
v) source $HOME/.bash_profile
vi) gradle -v should say gradle 2.2
2) in $HOME/.gradle/gradle.properties, you can set whether or not you want to use the gradle daemon by including a line that says:
org.gradle.daemon=true (gradle will use the daemon when appropriate)
or
org.gradle.daemon=false (it won't use the daemon)
3) in your project, myproj, which I assume will be in $HOME/projects/myproj
$HOME/projects/myproj/gradle.properties should look like:
grailsVersion=3.1.4 (or whatever version you are using)
gradleWrapperVersion=2.2 (again, answering your question)
4) in $HOME/projects/myproj/gradle/wrapper/gradle-wrapper.properties, the last line should say:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
in newer versions, this says gradle-2.9-bin.zip (it's what you originally wget'ed)
5) finally, 'cd $HOME/projects/myproj' and './gradlew bootRun' to run your project. or, 'gradle bootRun'. grails likes to use the wrapper via the ./gradlew command. Use './gradlew assemble' to build your .war. if you think you are not running the version you think you should be, use './gradlew clean --refresh-dependencies'.
good luck!

Have you looked at your gradle.properties file? Mine looks like this:
grailsVersion=3.0.11
gradleWrapperVersion=2.3
grails.groovyVersion=2.4.5
Not sure about downgrades. 2.3 has worked fine for me so far.

Related

java.nio.file.NoSuchFileException: /target/classes/META-INF/annotations/hudson.Extension when building Jenkins plugin

I have found a plugin for using StatsD with Jenkins (https://github.com/joemiller/jenkins-statsd-plugin) - however the HPI needs building because it is not available in Jenkins plugin repository nor is it aailable to download.
I followed the official instructions at https://wiki.jenkins.io/display/JENKINS/Plugin+tutorial, but the $ mvn package always exits with [ERROR] java.nio.file.NoSuchFileException: ~/src/jenkins-statsd-plugin/target/classes/META-INF/annotations/hudson.Extension.
I have tried using java 6, 7, 8 and 10 but to no avail.
I wonder if anybody else has come up against this problem building Jenkins plugins and what they're solution was?
I fixed this problem by setting JAVA_HOME to point to Oracle’s version of Java 8. It appears maven uses the JAVA_HOME environment variable, not your $PATH.
Edit: For extra context, Jenv was responsible for the version of Java in my $PATH.
I would like to post here my findings from various sources that worked for me as the accepted answer alone was not sufficient.
I had to downgrade my Java version back to 11 from 13.
I used this quick solution, which doesn't require you having JDK and Maven installed locally.
Moreover, deleting target/classes/META-INF/ directory before executing mvn install again was necessary.
Lastly, passing -Djenkins.version parameter to Maven is required so you need to do something like mvn -Djenkins.version=2.164 install
This will definitely get resolved by using java 1.8.* JDK.

Testing a Grails 2.5.3 app in Travis-CI tries to use Grails 2.4.4

I have an application built on Grails 2.5.3 (https://github.com/ppazos/cabolabs-ehrserver).
I'm trying to integrate Travis-CI to run the tests of my app when I do a commit to GitHub. Here is my travis config file (the one I ended after a couple of hours of trial and error without luck): https://github.com/ppazos/cabolabs-ehrserver/blob/master/.travis.yml
language: groovy
sudo: false
jdk:
- oraclejdk7
env:
- GRAILS_VERSION=2.5.3
before_install:
- rm -rf ~/.gvm
- curl -s get.sdkman.io | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- echo sdkman_auto_answer=true > ~/.sdkman/etc/config
- source "/home/travis/.sdkman/bin/sdkman-init.sh"
# dev null is to avoid the need for user input https://github.com/sdkman/sdkman-cli/issues/101
- sdk install grails $GRAILS_VERSION < /dev/null
- sdk use grails $GRAILS_VERSION
- grails -version
- sdk current grails
branches:
only:
- master
script: sdk use grails $GRAILS_VERSION &&
grails upgrade --non-interactive &&
grails clean &&
grails test-app -integration
The problem is that even sdkman reports that is using Grails 2.5.3 and grails version says the same, when the app is executed, I see this on Travis-CI UI:
|Loading Grails 2.4.4
|Configuring classpath
|Running pre-compiled script
It also tries to install old versions of plugins, not the version I have in my BuildConfig.
Here is the full output of the Travis-CI build:
https://travis-ci.org/ppazos/cabolabs-ehrserver
I'm new to Travis-CI and I don't seem to find the problem, any help is very welcome!
I previously used SDKMAN (AKA GVM) to build my Grails projects on Travis, but using the Grails wrapper is a more reliable, simpler, and faster solution. Here's my Grails 2.5.1 project that I build with the Grails wrapper - notice that the Travis script is much simpler than yours, and because I don't need to install SDKMAN and Grails each time the build is run, it ought to be much faster.
All you need to do is commit the wrapper dir, and the scripts grailsw and grailsw.bat - don't copy them from my project, use those that are generated for a Grails 2.5.3 project (because they might have changed since Grails 2.5.1).
The main problem was that I had an old pom.xml file in the project root and didn't knew that Travis-CI was using that to build the project. After I updated the pom (https://github.com/ppazos/cabolabs-ehrserver/commit/97d080bf9f7459732ca04faac10e6ae96d6ee3b3) it started to take the right version of Grails, v2.5.3, but another problem arose:
I have a JAR in my /lib folder that wasn't loaded by Maven, so the build failed because the missing classes. That is an internal lib developed my myself and it is only to be used by a couple of projects, so it is not published on any Maven repo.
Looking on the web, couldn't find any solution that works just to make Maven consider my JAR.

Which version of jdk can i use for building a maven project?

I'm going to build a maven project for the first time. I downloaded maven- 3.1.1 and I want to know if I can use jdk 1.7.0._05. If there is any other version that I need to use, please do specify.
Thanks :)
As far as I know there isn't any version that you are forced to use to build Maven project. You can simply run:
mvn -version
to see what version is used currently by Maven. This version should match the JDK you have set as JAVA_HOME, so in case if you want to change it, simply change your JAVA_HOME to different directory.
Have a look at System Requirements noted at the download page:
JDK: 1.5 or above (this is to execute Maven - it still allows you to build against 1.3 and prior JDK's)

create POM with junit 4

I use Maven 3.0.4 and want to have junit 4 by default.
My projects are created with the command :
$>mvn archetype:create -DgroupId=my.group.id -DartifactId=myArtifactId -DpackageName=my.package.name
This puts a depency to junit version 3.8.1 in the created pom.xml, dispite the fact that verion 4.8.1 is already present.
There are no dependencies to junit in my global settings.xml, and I haven't a local .m2/repository/settings.xml. I don't want to remove the old version 3.8.1., but want that all new projects are created with version 4.8.1
Can I do this in my settings.xml (global or local does not matter)? And if so what is the correct syntax?
A couple things:
archetype:create is deprecated by archetype:generate; please use generate, it's interchangeable with create in your example.
As for a solution, I'd say the simplest thing to do is generate your project, edit the pom to have the correct junit version; and then from within your project run:
mvn archetype:create-from-project
Which will create an archetype based on your modifications, you simply need to install this with:
cd target/generated-sources/archetype/
mvn install
Now you can create new maven projects with this new archetype as you like with:
mvn archetype:generate -DgroupId=my.group.id -DartifactId=newArtifact -DpackageName=my.package.name -DarchetypeArtifactId=myArtifactId-archetype -DarchetypeGroupId=my.group.id
Hopefully this helps.

setting environment variables

I'm setting up grails, and these are the commands the README indicates you should run for a unix machine. My problem is that the echo command doesn't output anything like it should. I double checked and have the grails folder in the right directory.
> set GRAILS_HOME=~/grails
> export GRAILS_HOME
> echo ${GRAILS_HOME}
~/grails
you need to set the path variable:
export GRAILS_HOME=/path/to/grails
export PATH=$PATH:$GRAILS_HOME/bin
For OS X Lion you add these lines this is to your ~/.bash_profile file. This is the same as your /Users/macUsername/.bash_profile. After saving this edit, new terminal windows will have this effect in place. You can also run source ~/.bash_profile to make the change happen in your current terminal window.
On another *nix you would edit a slightly different file.
The .bash_profile file holds commands that run every time you start your terminal.
Installation from Download
Prerequisites
Before you can start using Grails you will need to install a Java SDK (not just a JRE) and set the JAVA_HOME environment variable to the location of that SDK. The minimum required version of the SDK depends on which version of Grails you are using:
Java SDK 1.4+ for Grails 1.0.x and 1.1.x
Java SDK 1.5+ for Grails 1.2 or greater
Steps
Download the latest Grails release
Extract the archive into an appropriate location; typically C:\grails on Windows or ~/grails on Unix
Create a GRAILS_HOME environment variable that points to the path where you extracted the archive (eg C:\grails on Windows or ~/grails on Unix)
If you have not set the JAVA_HOME environment variable yet, create JAVA_HOME environment variable that points to the path where you have installed Java
Append a reference to the "bin" directory within the Grails directory to your PATH variable (eg %GRAILS_HOME%\bin on Windows or $GRAILS_HOME/bin on Unix). Note that, for Windows, both PATH and GRAILS_HOME must be defined at the same environment variable level (eg. 'System variables') rather than across environment variable levels (eg. PATH under 'System variables' and GRAILS_HOME under 'User variables')
Type "grails" at the command line, if a help message is displayed you are ready to start using Grails!
If you get an error message, try to chmod +x the grails script inside the bin directory.
Installation from Git (The Version Control Repository)
Prerequisites
In order to start using Grails from Git you need to have the following:
An installation of Java 1.5 or higher and have set your JAVA_HOME variable to the install location
A Git client
Steps
Check out Grails from the Git repository
by running: git clone git://github.com/grails/grails-core.git
Set the GRAILS_HOME environment variable to CHECKOUT_LOCATION/grails-core
Add the $GRAILS_HOME/bin directory to your PATH environment variable
What happens next depends on which branch you are working on.
For the 2.0.x and the 'master' branch:
Go to the GRAILS_HOME directory and run: ./gradlew install
That's it! You can now start developing in Grails using your custom copy of Grails!
For the 1.3.x branch:
Go to the GRAILS_HOME directory and run: ./gradlew libs
Then from the GRAILS_HOME directory run: ./gradlew install
That's it! You can now start developing in Grails using your custom copy of Grails!
For the 1.2.x branch:
If you don't have Ant 1.7 (or later) installed, you will need to
set ANT_HOME to $GRAILS_HOME/ant
add $ANT_HOME/bin to your PATH environment variable
you may need to give the scripts in $ANT_HOME/bin execute permissions
Increase the java memory to 1024M by setting ANT_OPTS=-Xmx1024M
Go to the GRAILS_HOME directory and type ant jar to build Grails
That's it! You can now start developing in Grails using your custom copy of Grails!
Confirm your grails install by grails -version

Resources