groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Moore <p.f.mo...@gmail.com>
Subject Re: What is the best replacement for running scripts using groovy-all?
Date Wed, 19 Dec 2018 22:33:54 GMT
On Wed, 19 Dec 2018 at 21:23, James Kleeh <james.kleeh@gmail.com> wrote:
>
> Paul,
>
> The best solution is to use Maven or Gradle to create an all-in-one (fat) jar that you
can ship and run with java -jar
>
> Gradle has a shadow plugin and Maven has a shade plugin to do just that.

Thanks. I'd come to the conclusion that Gradle was likely the solution
I should be looking at, and I've spent the evening trying to set up a
basic Gradle script that does what I want. After a lot of
experimentation, I came up with the following, which seems to do what
I want:

---------- start build.gradle ----------

version = "0.1"

configurations {
    deploy
}

dependencies {
    deploy 'org.codehaus.groovy:groovy-all:2.5.4'
}

repositories {
    jcenter()
}

task copyDeps(type:Copy, group: "Custom", description: "Copies project
dependencies") {
    from configurations.deploy.collect { it.absolutePath }
    into "dest/lib"
}

task copy(type: Copy, group: "Custom", description: "Copies sources to
the dest directory") {
    from "src"
    include "*.groovy"
    into "dest"
}

task deploy(type:Zip, group: "Custom", description: "Build a deployment zip") {
    dependsOn copyDeps
    dependsOn copy
    from "dest"
    setArchiveName "${project.name}-${project.version}.zip"
}

---------- end build.gradle ----------

It doesn't create a fat jar yet, but I can look into setting that up.
The various existing plugins seem to be dependent upon the
infrastructure set up by the java plugin, which I don't really
understand (or need, as far as I can tell) so they may not be of much
help. But I'm not sure what I need to do yet to write my own.
Something simple like

task customFatJar(type: Jar) {
    dependsOn copyDeps
    baseName = 'all-in-one-jar'
    from "dest/lib"
}

gives me an "all-in-one-jar.jar" that contains the dependency jars
directly included, rather than being unpacked. So there's more I need
to do here...

Paul

Mime
View raw message