4

Consider the following scenario.

I have a Java 1.8 project that depends on a java 8 artifact called foo-bar and a java 5 artifact called baz-qux. baz-qux also depends on foo-bar. But it uses the special slimmed down java 5 build called foo-bar-java5. Thus by including baz-qux into my project, I transitively bring in foo-bar-java5. In the end I have an undesirable state where I now have foo-bar and foo-bar-java5. Apparently there's no way to do a global exclude. So I can't just exclude foo-bar-java5. Instead, I must clutter up my cluttered pom and exclude it everywhere it will be pulled in transitively.

With that said, is there any way I can specify that foo-bar provides foo-bar-java5? Or is the only option to truly exclude foo-bar-java5 everywhere?

Jason Thompson
  • 4,643
  • 5
  • 50
  • 74
  • Can you not version it differently? `foo:bar:1.0` and `foo:bar:1.0-java5`? Or do you have no control over that? – John Vint May 01 '15 at 19:50
  • You could have the two different dependencies in a profile, but that is generally not a good idea. I would go the simple way and provide a seperate Java 5 POM, especially since you can than forget about it and never touch it again :) – eckes May 01 '15 at 19:50
  • You can declare foo-bar-java5 explicitly in scope. Then it will not be included in list of runtime jars. – Sergey Alaev May 01 '15 at 19:58
  • foo-bar and foo-bar-java5 is a 3rd party library. – Jason Thompson May 01 '15 at 20:28

1 Answers1

1

Here is an answer from another question that may work for you:

https://stackoverflow.com/a/9623517/2879838

Basically, explicitly list the foo-bar-java5 as a dependency in your project and list it as provided. This will tell maven not to put that jar into the archive during the build. This should be a lot less messier than excluding it everywhere.

Community
  • 1
  • 1
David Fleeman
  • 2,588
  • 14
  • 17
  • afaik, mvn eclipse:eclipse will still bring in a provided dependency. – Jason Thompson May 01 '15 at 20:29
  • Correct, your IDE will pull in the lib as a dependency, but the archive build will exclude the lib. If you need your IDE to not have the lib pulled down into your project, then, yeah, I would say you need to explicitly exclude it everywhere in your pom.xml – David Fleeman May 01 '15 at 20:44