Hi,
I am trying to create a jar with its dependencies.
I have two sub-projects “app” and “lib” with “app” depending on “lib”.
The ‘jar’ task fails and gives this message:
> Task :app:jar FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:jar'.
> Cannot convert the provided notation to a File or URI: ZIP '/Users/ ... /lib/build/libs/lib.jar'.
The following types/formats are supported:
- A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
- A String or CharSequence URI, for example 'file:/usr/include'.
- A File instance.
- A Path instance.
- A Directory instance.
- A RegularFile instance.
- A URI or URL instance.
- A TextResource instance.
I reproduce this error with Gradle versions 7.1.1 then 7.0 then 6.9 (I have not tested other versions).
The “build.gradle” file for “app” is as follows:
plugins {
id 'java-library'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(15)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(dir: '/Users/ ... /lib/build/libs', include: '*.jar')
}
tasks.named('jar') {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': '1.0'
'Main-Class': 'com.mypackage.TestJarWithDependencies')
from configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Since I haven’t found any different examples to create a jar with its dependencies, I’m wondering why there is this error message.
But above all, I would like to know how to create a nice jar file with all its dependencies.
In this test example I access a personal library but the final goal is to create a jar that uses Java libraries such as JavaFx, Hibernate etc.