Should banks "provide" dependencies?

We are creating an ear that will run in Websphere where j2ee.jar is provided.

Now we have a situation where ejb (name it ejb.jar) depends on another jar (name it util.jar), which depends on j2ee.jar.

If mark j2ee.jar in pom util.jar is “provided”, ejb.jar will not build because the provided is not transitive. If we mark it as “compilation”, it can become an ear dependency compilation if we do not overwrite the area.

What is the best approach? Should util.jar provide dependencies, even if it's just a modest jar? Or if banks only have dependency compilation?

+5
source share
1 answer

JARs can provide dependencies ... but a user who has a dependency on it needs to make sure that this dependency is indeed provided at runtime. Since the provided dependencies are not transitive, they must also make sure that they are not dependent on it to compile; but if they do, it would be best practice to declare it explicitly by compiling (or provided) the domain and not rely on some form of transitivity (see analyze for the Dependency Plugin, which, for example, uses lists but not declared dependencies).

  • The provided dependencies in the JAR can be useful in creating executable JARs. Consider building a uber-jar (a JAR with classes that include all its dependencies): you can say that a particular dependency should not end in uber-jar, since starting this container will ensure this at runtime.
  • In addition, the JAR may need to depend on the compilation of its code, but in fact it does not need to be run; as an example, consider Maven plugins that declare maven-plugin-annotations as a provided dependency because they only need the annotations that need to be built.
  • Endpoint: There are JARs that have a good idea in which context they will be used: Spring WebMVC, for example, definitely depends on the servlet API to compile, but at run time it knows it will be used in the context of the Java EE and what the Servlet API will be provided by the Java EE server.

As a rule, although, in addition to the above cases, you probably do not want to provide JAR dependencies inside a JAR project: it must be the client who must decide whether your dependencies on compilation will be provided for their particular case, and let the client override scope. As a library writer, you really don't know how your library will be used.

In your specific case, since ejb.jar really needs j2ee.jar to compile, it would be better to declare this dependency with compilation or even with the scope provided in your case, no matter what util.jar has for j2ee.jar . (I will notice that it is too difficult for the JAR utility to use JARs from the Java EE web application classes.)

+2
source

Source: https://habr.com/ru/post/1260287/


All Articles