0

It seems to me that it would be really useful to have the dependencies of a jar listed in its Manifest, possibly as an optional field. Without this feature, it is near impossible to know what a jar depends on, without finding it on the web somewhere, or using a dependency management tool, or something along those lines. Now that everyone is using the whole artifact ID, group ID, version convention, I would imagine this would greatly simplify the tools needed to setup a project.

I find myself needing to use maven more than I would like to because it's such a hassle to figure out if something needs Apache commons or logging or whatever the case may be, why not just have the jars listed in some Manifest Field?

Derrops
  • 7,651
  • 5
  • 30
  • 60
  • Are you asking how can you add the dependencies to the Manifest are you complaining that some jars you found do not have it? – Tunaki Sep 25 '15 at 09:44
  • Listing dependencies might be nice, but then there's dependencies of dependencies etc, so tools like Maven and Gradle would still have their place. – NickJ Sep 25 '15 at 09:49
  • @Tunaki are you saying some jars are doing this already? I haven't come across any. – Derrops Sep 25 '15 at 13:48

3 Answers3

1

I think maven is more convenient. Listing dependencies in a manifest is very ambiguous, you don't specify such elements as group, location or repository, even you don't have security on the name of the dependencies.

Describing dependencies in a a manifest is possible, but how do you reference this dependencies? It depends on every developer, and thus can lead to use different names, different jar packaging, etc.

Maven is more complex but also more adecuate, because it defines repositories, groups, artifacts, version and packagins which in the end helps to reduce ambiguity and allows you to rely on a trusty system.

When using maven, a pom copy is stored inside META-INF directory and here you can find dependencies. This is more useful than listing dependencies into manifest.

malaguna
  • 4,183
  • 1
  • 17
  • 33
  • Fair enough, I wasn't meaning to make a whole project this way, just would be allot easier for me if all the jars are on maven central and I am just doing a quick demo, can't stand making a pop every single time. – Derrops Sep 25 '15 at 13:50
  • Didn't realize the pom was in there. Is this always the case? I swear I checked, but maybe I had a noob moment. – Derrops Sep 25 '15 at 13:52
  • Actually, not always, it is configurable with the [`addMavenDescriptor`](http://maven.apache.org/shared/maven-archiver/index.html) attribute of [`maven-jar-plugin`](https://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#archive). – Tunaki Sep 25 '15 at 14:44
1

Take a look at OSGI (http://www.osgi.org/Main/HomePage). It provides among others, dependency information for packages (import and export statements) on a jar.

In General: Dependencies are usually not easy and straight-forward (they might differ in scope, version, etc.). EAR and WAR specification from JEE try something similar for application servers.

1

Because dependency management is harder than it might first seem, so Java has not provided a mechanism.

If it were to list the dependencies it would need some format for describing each dependency. That would have to be a name plus a version selector.

Java is cross platform, so the name can not be a file name, because filenames are not portable. It can not be the "name" of a JAR because some implementations might be spread over multiple JARs. Names would have to be unique. Who ensures that?

A JAR might access a service through an abstract API, and so might require require an implementation, but no specific implementation. How would that be expressed?

A JAR might work with several versions of another JAR. How would that be expressed? How would you indicate it worked with a range of versions? Version IDs are rarely numbers, and so do not have an obvious ordering.

Raedwald
  • 46,613
  • 43
  • 151
  • 237