Let’s say I have a parent project with two subprojects “lib” and “app”.
The “lib” project depends on the jackson-core library, v2.1.0.
The “core” project depends on the “lib” project (it doesn’t make use of jackson-core directly).
I want to create a Gradle task to automatically generate a shell script that launches “app” with the right classpath. Here’s my attempt:
task launcher(dependsOn: compileJava) {
String packageName = projectDir.name.replace(’-’, ‘_’)
String mainClassName = ‘com.dropbox.sdk.examples.’ + packageName + ‘.Main’
project.buildDir.mkdirs()
File launcherFile = new File(project.buildDir, “run”)
Writer out = new OutputStreamWriter(new FileOutputStream(launcherFile), “UTF-8”)
try {
out.write("#! /bin/sh\n")
out.write(“java -cp " + project.runtimeClasspath.getAsPath() + " " + mainClassName + " “$@””)
}
finally {
out.close()
}
ant.chmod(file: launcherFile.path, perm: “+x”)
}
build.dependsOn launcher
This generates the script “run”, but it doesn’t have the correct classpath. The classpath in the script has the following entries: 1. /home/kannan/gradle-deps/app/build/classes/main 2. /home/kannan/gradle-deps/app/build/resources/main 3. /home/kannan/gradle-deps/lib/build/libs/lib.jar
My first issue is with the 3rd entry. I would like that to point to the “classes” directory of the “lib” project.
My second issue is that the “jackson-core” JAR file isn’t included.
Any tips on what I can do about this?