Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven conditional dependencies

We would like to bundle library dependencies from (Alfresco or Jackrabbit or ...) based on the customer choice. The number of dependencies actually varies based on the chosen vendor. How do we provide hooks at the maven level, so that the final product just includes the dependent jars as per customer selection.

like image 364
Joe Avatar asked Mar 09 '10 11:03

Joe


People also ask

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

How does Maven avoid transitive dependencies?

Exclude the transitive dependencyOpen the dependency POM and find the transitive dependency you want to exclude. Copy groupId and artifactId . In your project POM, underneath your active dependency, enter exclusions and using code completion paste the copied info of the dependency you want to exclude.

Does Maven support transitive dependencies?

Transitive Dependencies. Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. This feature is facilitated by reading the project files of your dependencies from the remote repositories specified.


1 Answers

You could achieve this by putting the needed dependencies into vendor-specific profiles in your pom:

<profiles>
    <profile>
        <id>Alfresco</id>
        <dependencies>
            ...
        </dependencies>
    </profile>
    <profile>
        <id>Jackrabbit</id>
        <dependencies>
            ...
        </dependencies>
    </profile>
</profiles>

Then you can activate the desired profile for your build like:

mvn -PJackrabbit install
like image 169
Péter Török Avatar answered Oct 15 '22 16:10

Péter Török