1

Guys I need to find out some way to include or exclude dependency while compile my code in maven (maven-compiler-plugin), I don't want to include all dependency in my class path, just few of them which will be used by java class file to be compile.

Is there any to do this ?

Afgan
  • 1,022
  • 10
  • 32
  • I'm not sure I understand the question. Can you give an example? Why would Maven's standard 'exclusions' mechanism not work for your requirement? – sisyphus Apr 13 '16 at 12:26
  • You can use the "scope" element. See the answer here: http://stackoverflow.com/questions/6646959/difference-between-maven-scope-compile-and-provided-for-jar-packaging – chrisl08 Apr 13 '16 at 12:34
  • Thanks for comment guys, My requirement is like :I have Class A, which should compiled two times with same dependency but different version of it(Two different jar almost same implementation with few changes). hence I need one dependency at a time two compile my Class A. – Afgan Apr 14 '16 at 05:37

1 Answers1

2

You need to set the scope of the dependency to provided. This will make maven assume that the dependencies will be available at run-time. e.g.

<dependency>
  <groupId>group-a</groupId>
  <artifactId>artifact-b</artifactId>
  <version>1.0</version>
  <scope>provided</scope>
</dependency>

It is explained much better here -

Dependency scope

Neil Mason
  • 86
  • 5
  • Thanks for answer, please refer my requirement from my comment in question , I know fundamental of dependency scope, I need to specify dependency in my maven compiler plugin some how. I hope you get it. – Afgan Apr 14 '16 at 06:00
  • That's awesome, thanks, I was looking for this. – Yougeshwar Khatri Mar 28 '21 at 10:32