Question

Is there a way I can set up dependancies according to a given condition when I buid the maven project.

mvn package someCondition

So if I say mvn install A it should add one dependancy and if a say mvn install B it should add another type of dependancy.

Please help. Thank You

P.S. Is there a way I can do this by creating multiple profiles?

Was it helpful?

Solution

Using profile is the most straight-forward way.

in brief, consider having something like this:

<project>
  ...
  <profiles>
    <profile>
      <id>profile-a</id>
      <dependencies>
        <dependency>
          // dependency 1
        </dependency>
      </dependencies>
    </profile>
    <profile>
      <id>profile-b</id>
      <dependencies>
        <dependency>
          // dependency 2
        </dependency>
      </dependencies>
    </profile>
  <profiles>
</project>

Then you can simply do mvn install -P profile-a which will do what you ask for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top