[ACCEPTED]-How can I create a pathing jar in Gradle-gradle
Here is a tested solution:
task pathingJar(type: Jar) {
appendix = "pathing"
doFirst {
manifest {
attributes "Class-Path": configurations.compile.files.join(" ")
}
}
}
compileGroovy {
dependsOn(pathingJar)
classpath = files(pathingJar.archivePath)
}
Depending on your 6 exact requirements, you might have to tweak 5 this a bit. For example, if you have tests 4 written in Groovy, you will also need a 3 pathing Jar for the test compile class path. In 2 this case you'll need to repeat above configuration 1 as follows:
task testPathingJar(type: Jar) {
appendix = "testPathing"
doFirst {
manifest {
attributes "Class-Path": configurations.testCompile.files.join(" ")
}
}
}
compileTestGroovy {
dependsOn(testPathingJar)
classpath = files(testPathingJar.archivePath)
}
I finally got the "pathing jar" idea to 8 work. I consider this to be a permanent 7 workaround. This could be considered a solution 6 if it is made part of gradle itself.
The 5 original pathing jar code was provided by 4 Peter, but it didn't work. The problem: classpath 3 elements referenced in the pathing jar must 2 be relative to the location of the pathing 1 jar. So, this appears to work for me.
task pathingJar(type: Jar , dependsOn: 'cleanPathingJar') {
/**
* If the gradle_user_home env var has been set to
* C:\ on a Win7 machine, we may not have permission to write the jar to
* this directory, so we will write it to the caches subdir instead.
* This assumes a caches subdir containing the jars
* will always exist.
*/
gradleUserHome = new File(gradle.getGradleUserHomeDir(), "caches")
relativeClasspathEntries = configurations.compile.files.collect {
new File(gradleUserHome.getAbsolutePath()).toURI().
relativize(new File(it.getAbsolutePath()).toURI()).getPath()
}
appendix = "pathing"
destinationDir = gradleUserHome
doFirst {
manifest {
attributes "Class-Path": relativeClasspathEntries.join(" ")
}
}
}
compileGroovy {
dependsOn(pathingJar)
classpath = files(pathingJar.archivePath)
}
This is what helped me:
"The filename or extension is too long error" using gradle
In other words: use 5 the com.github.ManifestClasspath plugin.
The 4 other solutions did not work for me because 3 the actual project main class ended up no 2 being included in the classpath at execution 1 time.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.