• Startseite
  • Über mich
  • Portfolio
    • Eventmanagement
    • Technologie
      • Multitouch-Surface
      • Multitouch-Table
    • Smartphone-Apps
    • Unternehmen
    • Presse
  • Programmierung
  • Auto
  • Wirtschaftsinformatik

Patrick Hütter

Mein Blog rund um Softwareentwicklung, Online-Marketing, StartUps, Gründung, Unternehmertum, Trends and more

[HowTo] Build groovy project and package as jar (with all dependencies) for easy distribution with gradle

0
  • by Patrick Hütter
  • in Code-Snippets · Programmierung · Projektmanagement · Shell
  • — 10 Jan, 2014

I just moved from maven to gradle within one of our groovy projects. Gradle just works fine and with it you’re able to distribute your application to other developers without the need of complicated instructions how to install the build tool.

gradle

I collected all you need in this simple build.gradle script for creating a jar with your dependencies with „gradle build“ and also the option to run your application directly by running „gradle run“ in the project directory.
In this script is a task, called „wrapper“ contained. You can run „gradle wrapper“ to run this task within your project directory and gradle will install the gradle wrapper files into it.

gradlew
gradlew.bat
gradle/wrapper/
gradle-wrapper.jar
gradle-wrapper.properties

Bundle this files with your project (for example into version control) and everyone who gets your code can build your project running the wrapper wich automatically downloads gradle if it’s missing.

At last the build.gradle file. If you want to use it, place it in your project directory root.

apply plugin:'application'
apply plugin: 'groovy'

// change to your mainClass with full package name
mainClassName = "main.groovy.MyMainClass"

repositories {
 // define your repositories here
 mavenCentral()
}

dependencies {
 // define your dependencies here
 compile 'org.codehaus.groovy:groovy-all:2.2.0'
 // for example
 // compile 'org.jsoup:jsoup:1.7.2'
}

jar {
 doFirst {
 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
 }

 // This is optional, needed if you have signature problems while starting your created jar.
 // This often happens while including foreign depdendencies wich are signed. 
 exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

 // change to your main class with full package name
 manifest.attributes("Main-Class":"main.groovy.MyMainClass")
}
Share

Tags: build automationgradleGroovyscript

— Patrick Hütter

Patrick ist Gründer und Geschäftsführer der encircle360 GmbH. Er liebt Technologie und kennt sich sehr gut im Bereich Softwareentwicklung, u.a. auf JVM basierten Technologien wie Spring Boot, VertX, Akka, Groovy, Scala & Elasticsearch aus.

  • Previous story Shortinfo: Infos zum Thema Speedreading
  • Next story Running Grails applications on the Raspberry Pi
  • Du suchst richtig gute Beratung im Bereich Software & IT?

    encircle360
  • Neueste Beiträge

    • Running headscale with headscale-admin (UI), letsencrypt & docker-compose in dual stack with IPv4 and IPv6
    • Groovy & Grails suchen einen neuen Hauptsponsor
    • Unitymedia DNS Probleme und Lösungsmöglichkeiten für Mac OS X, Windows und den eigenen Router
    • Running Grails applications on the Raspberry Pi
    • [HowTo] Build groovy project and package as jar (with all dependencies) for easy distribution with gradle
  • Neueste Kommentare

    • nototok bei Running headscale with headscale-admin (UI), letsencrypt & docker-compose in dual stack with IPv4 and IPv6
    • Muiz bei Running headscale with headscale-admin (UI), letsencrypt & docker-compose in dual stack with IPv4 and IPv6
    • John Tucker bei Running headscale with headscale-admin (UI), letsencrypt & docker-compose in dual stack with IPv4 and IPv6
    • Bastlerwastl bei HowTo: Squid Proxy Server unter Debian schnell eingerichtet
    • PatrickHuetter bei So geht’s: Macbook mit zwei externen Monitoren verbinden
  • Kategorien

    • Allgemein
    • Android
    • Code-Snippets
    • Datenbanken
    • Elektrotechnik
    • Licht
    • Linux
    • Mac
    • Messe
    • Online-Marketing
    • Programmierung
    • Projektmanagement
    • SEM
    • SEO
    • Server
    • Shell
    • Social Media
    • Web
  • Weiterführende Links

    • Price API
    • encircle360
    • sellytics
  • Impressum
  • Datenschutz

© Patrick Hütter