I have a working little application made in Groovy. At the moment I can test it on the command line, but I need to integrate it with a Jenkins server. Hence I have thought to integrate it with Gradle to produce test output in a standard format that Jenkins can read. (Please, consider that I am new to Groovy, Gradle, Jenkins and the JVM environment in general).
At the moment all my tests live inside a single MyTest
class that extends GroovyTestCase
. I can run it with a little bash script like
#! /bin/bash
DIR=$( cd "$( dirname "$0" )" && pwd )
LIBS="$DIR/lib/*"
groovy -cp "$LIBS" path/to/MyTest.groovy
There are multiple things that I do not like in this layout:
- First, I would like to separate the tests into multiple classes and join them into a test suite, but a test case had the advantage that it is automatically runnable in Groovy
- Second, as I said, I would like to be able to obtain a test report to be consumed by Jenkins
- Third, I do not know if putting all required jars into a
lib
directory is a good practice - probably not.
Gradle seems exactly the tool that I need. But all the documentation I find assumes previous knowledge of Java, Ant, Maven and the whole ecosystem.
What are the basic steps to create a working Gradle project?
I have reorganized the directory structure as suggested here, but I do not understand how to declare dependencies. For instance with this build.gradle
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.0'
runtime group: 'org.apache.log4j', name: 'log4j', version: '1.2.0'
}
I obtain the error
unable to resolve class org.apache.log4j.Level
@ line 5, column 1.
import org.apache.log4j.Level
^
If I change repositories to
repositories {
mavenCentral()
flatDir { dirs 'lib' }
}
to get log4j
from my lib
directory, I get
A problem occurred evaluating root project 'alfred'.
Cause: Could not find method flatDir() for arguments [build_3urmo05tgpv3e97u7h8ij47i3$_run_closure1_closure3@64c7f7c4] on root project 'alfred'.