Is it possible to declare multiple versions of the same dependency in a Maven repo?
I need these dependencies all at once:
<dependency> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId> <version>1.7.9-R0.2</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId> <version>1.7.2-R0.3</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId> <version>1.6.4-R2.0</version> <scope>compile</scope> </dependency>
Because each of them contains a different package I care about:
org.bukkit.craftbukkit.v1_6_R3
org.bukkit.craftbukkit.v1_7_R1
org.bukkit.craftbukkit.v1_7_R3
If I declare dependencies as shown in the first snippet, only the last one will take effect. Is there any way to achieve this in Maven?
@Edit Any workaround, maybe?
Enforcer can help developers solve dependency conflicts in Maven by analyzing all libraries declared in the POM file. The plugin uses a lot of different rules, but we are only interested in one: dependencyConvergence – ensures all dependencies converge to the same version.
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.
Run mvn clean It will tell you your duplicate dependencies. Then delete them.
No. Maven will only resolve one dependency in your module and will omit the other versions to avoid any conflict. Even if multiple versions of the same dependency are used in the whole dependency hierarchy, Maven will pick one version using the "nearest in the dependency tree" strategy.
It is possible to specify different dependency versions using different profiles. For each version of Bukkit a profile can be defined and activated. Still if you activate more than one profile, only one version would be used.
<profiles> <profile> <id>Bukkit_1_7_9_R02</id> <activation> ... </activation> <dependencies> <dependency> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId> <version>1.7.9-R0.2</version> <scope>compile</scope> </dependency> </dependencies> </profile> <profile> <id>Bukkit_1_7_2_R03</id> <activation> ... </activation> <dependencies> <dependency> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId> <version>1.7.2-R0.3</version> <scope>compile</scope> </dependency> </dependencies> </profile> ... </profiles>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With