Get Started
Let’s start with a simple example: Download, unzip and validate an INTERLIS transfer file:
Java flavour
You need Java 1.8 and Gradle >= 5.1.1 (and < 6) installed on your machine.
Create a build.gradle file and paste the following code into the file:
import java.nio.file.Paths
import ch.so.agi.gretl.tasks.*
import ch.so.agi.gretl.api.*
import de.undercouch.gradle.tasks.download.Download
{
buildscript {
repositories { url "https://jars.interlis.ch" }
maven { url "https://repo.osgeo.org/repository/release/" }
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://s01.oss.sonatype.org/service/local/repositories/releases/content/" }
maven { url "https://s01.oss.sonatype.org/service/local/repositories/snapshots/content/" }
maven mavenCentral()
}
}
{
plugins "de.undercouch.download" version "4.1.2"
id "ch.so.agi.gretl" version "2.3.426"
id }
'validateData'
defaultTasks
.register('downloadFile', Download) {
tasks"https://files.geo.so.ch/ch.so.agi.av.dm01_ch/aktuell/2549.ch.so.agi.av.dm01_ch.itf.zip"
src file("2549.ch.so.agi.av.dm01_ch.itf.zip")
dest true
overwrite }
.register('unzipFile', Copy) {
tasks'downloadFile'
dependsOn zipTree(Paths.get("2549.ch.so.agi.av.dm01_ch.itf.zip"))
from file(".")
into "**/*.itf"
include }
.register('validateData', IliValidator) {
tasks'unzipFile'
dependsOn = ["2549.ch.so.agi.av.dm01_ch.itf"]
dataFiles }
To run your first GRETL job just type gradle
in the terminal - in the same directory where you saved the build.gradle file - and hit enter. On the first run, it will download a lot of dependencies (external libraries). Be patient and after downloading everything it will actually run the job and should finish with BUILD SUCCESSFUL
.
If you want some more logging output, use gradle -i
and you should see e.g. the well known output from ilivalidator.
Docker flavour
You can build your very own image or just use docker.io/sogis/gretl:latest. Since the image makes use of an init.gradle file, the build.gradle file looks a little bit different:
import java.nio.file.Paths
import ch.so.agi.gretl.tasks.*
import ch.so.agi.gretl.api.*
import de.undercouch.gradle.tasks.download.Download
: 'ch.so.agi.gretl'
apply plugin: 'de.undercouch.download'
apply plugin
'validateData'
defaultTasks
.register('downloadFile', Download) {
tasks"https://files.geo.so.ch/ch.so.agi.av.dm01_ch/aktuell/2549.ch.so.agi.av.dm01_ch.itf.zip"
src file("2549.ch.so.agi.av.dm01_ch.itf.zip")
dest true
overwrite }
.register('unzipFile', Copy) {
tasks'downloadFile'
dependsOn zipTree(Paths.get("2549.ch.so.agi.av.dm01_ch.itf.zip"))
from file(".")
into "**/*.itf"
include }
.register('validateData', IliValidator) {
tasks'unzipFile'
dependsOn = ["2549.ch.so.agi.av.dm01_ch.itf"]
dataFiles }
Run the following Docker command in the directory where the build.gradle file is stored:
docker run -i --rm --name gretl --entrypoint="/bin/sh" -u $UID -v $PWD:/home/gradle/project sogis/gretl:latest -c 'gretl'
The most important part is the bind mount of the working directory ($PWD
) to /home/gradle/project/ in the image. The image expects the build.gradle file in this specific directory.
If you want it a less verbose - especially if the run command gets more and more complex by adding more options - you can use e.g. a shell script.