Skip to content

Instantly share code, notes, and snippets.

@pcdv
Created January 3, 2014 11:05
Show Gist options
  • Save pcdv/8236256 to your computer and use it in GitHub Desktop.
Save pcdv/8236256 to your computer and use it in GitHub Desktop.
This experimental script uses Gradle to build a classpath from a project's dependencies then run a given java class
#!/bin/bash
# Example: gradlerun path/to/ivyrepo com.example:mylib:+ com.example.MyMainClass arg1
REPO=$1
DEP=$2
MAIN=$3
ARG=$4
shift 4
SCRIPT=/tmp/gradlescript$$
cat > $SCRIPT << EOF
apply plugin: 'java'
repositories {
mavenCentral()
ivy {
url "$REPO"
}
}
dependencies {
runtime "$DEP"
}
task(main, type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = "$MAIN"
args "$ARG"
}
EOF
trap "rm -f $SCRIPT" 0
gradle -b $SCRIPT -q main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment