Skip to content

Commit bf8400d

Browse files
c-dilkstongtongcao
authored andcommitted
doc: explain how to deal with dependency convergence errors (#837)
* doc: explain how to deal with dependency convergence errors * doc: `mvn` command * fix: ) * style: better comments * doc: add comments to the consumers too
1 parent a90755a commit bf8400d

File tree

5 files changed

+70
-19
lines changed

5 files changed

+70
-19
lines changed

common-tools/clas-tracking/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</dependency>
2525
<dependency>
2626
<groupId>org.ejml</groupId>
27-
<artifactId>ejml-simple</artifactId>
27+
<artifactId>ejml-simple</artifactId> <!-- WARNING: don't override the version number from the top-level dependencyManagement; see `docs/dependency_conflicts.md` -->
2828
</dependency>
2929
<dependency>
3030
<groupId>gov.nist.math</groupId>

common-tools/coat-libs/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@
3838
<dependency>
3939
<groupId>j4ml</groupId>
4040
<artifactId>j4ml-neuroph</artifactId>
41-
<version>0.9-SNAPSHOT</version>
4241
</dependency>
4342

4443
<dependency>
4544
<groupId>j4ml</groupId>
4645
<artifactId>j4ml-clas12</artifactId>
47-
<version>0.9-SNAPSHOT</version>
4846
</dependency>
4947

5048
<dependency>

docs/dependency_conflicts.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Handling Dependency Conflicts
2+
3+
We have a `dependencyManagement` section in [the top-level `pom.xml`](/pom.xml); some of the dependencies within are used to set versions of certain transitive dependencies. For example, let's say we have dependencies `dep:A`, `dep:B`, and `dep:C`.
4+
5+
- `dep:A` depends on version 1.1 of `dep:C`
6+
- `dep:B` depends on version 1.5 of `dep:C`
7+
8+
Coatjava depends on `dep:A` and `dep:B`, and so the `maven-enforcer-plugin` will complain about a "dependency convergence error" of `dep:C`, since the version numbers are different (1.1 vs. 1.5).
9+
10+
To resolve this conflict, a typical strategy is to choose the _later_ version of the two, in this case, `dep:C` version 1.5. We can do this by explicitly defining dependency `dep:C` in a `dependencyManagement` section as such:
11+
12+
```xml
13+
<dependency>
14+
<groupId>dep</groupId>
15+
<artifactId>C</artifactId>
16+
<version>1.5</version>
17+
</dependency>
18+
```
19+
20+
Coatjava will then use 1.5 as needed.
21+
22+
Dependabot, however, will routinely try to update the `dep:C` version, to the _latest_ available version of `dep:C`. When this happens, please do the following:
23+
24+
1. Comment out the `dependency` specification
25+
2. Rebuild coatjava, which will cause `maven-enforcer-plugin` to complain; that will tell you the versions
26+
- alternatively, run `mvn enforcer:enforce -Drules=dependencyConvergence`, but that may not exclude dependencies that we _don't_ want to enforce convergence on (_e.g._, `com.google.protobuf:protobuf-java`)
27+
3. Update the version number, if needed, by choosing the _later_ of the two conflicting versions
28+
4. Unless `dep:A` or `dep:B` are keeping _their_ version of `dep:C` dependency up-to-date, you will likely find that Dependabot is suggesting a version that is _too_ new; in that case, just close Dependabot's PR and await updates of `dep:A` or `dep:B`

pom.xml

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<dependency>
114114
<groupId>org.jlab.coda</groupId>
115115
<artifactId>jclara</artifactId>
116-
<version>4.3-SNAPSHOT</version>
116+
<version>4.3-SNAPSHOT</version> <!-- WARNING: if changed, check the `com.google.code.gson:gson` version; see `docs/dependency_conflicts.md` -->
117117
</dependency>
118118

119119
<dependency>
@@ -144,13 +144,31 @@
144144
<dependency>
145145
<groupId>org.jlab.jnp</groupId>
146146
<artifactId>jnp-hipo</artifactId>
147-
<version>2.0-SNAPSHOT</version>
147+
<version>2.0-SNAPSHOT</version> <!-- WARNING: if changed, check the `net.objecthunter:exp4j` version; see `docs/dependency_conflicts.md` -->
148148
</dependency>
149149

150150
<dependency>
151151
<groupId>org.jlab.jnp</groupId>
152152
<artifactId>jnp-hipo4</artifactId>
153-
<version>4.3-SNAPSHOT</version>
153+
<version>4.3-SNAPSHOT</version> <!-- WARNING: if changed, check the `net.objecthunter:exp4j` version; see `docs/dependency_conflicts.md` -->
154+
</dependency>
155+
156+
<dependency>
157+
<groupId>j4ml</groupId>
158+
<artifactId>j4ml-neuroph</artifactId>
159+
<version>0.9-SNAPSHOT</version>
160+
</dependency>
161+
162+
<dependency>
163+
<groupId>j4ml</groupId>
164+
<artifactId>j4ml-data</artifactId>
165+
<version>0.9-SNAPSHOT</version>
166+
</dependency>
167+
168+
<dependency>
169+
<groupId>j4ml</groupId>
170+
<artifactId>j4ml-clas12</artifactId>
171+
<version>0.9-SNAPSHOT</version> <!-- WARNING: if changed, check the `org.ejml:ejml-simple` version; see `docs/dependency_conflicts.md` -->
154172
</dependency>
155173

156174
<dependency>
@@ -165,33 +183,43 @@
165183
<version>1.0.3</version>
166184
</dependency>
167185

168-
<dependency>
186+
<dependency> <!-- sets version number for all 'ai.djl' dependencies -->
169187
<groupId>ai.djl</groupId>
170188
<artifactId>bom</artifactId>
171-
<version>0.34.0</version> <!-- sets version number for all 'ai.djl' dependencies -->
189+
<version>0.34.0</version> <!-- WARNING: if changed, check the `com.google.code.gson:gson` version; see `docs/dependency_conflicts.md` -->
172190
<type>pom</type>
173191
<scope>import</scope>
174192
</dependency>
175193

176194
<!-- BEGIN DEPENDENCY CONFLICT RESOLUTION -->
177-
<!-- the following dependency versions are specified to resolve dependency tree conflicts; see also exclusions in `maven-enforcer-plugin` -->
178-
179-
<dependency> <!-- conflict between `org.jlab.jnp:jnp-hipo:jar:2.0-SNAPSHOT` and `org.jlab.jnp:jnp-hipo4:jar:4.3-SNAPSHOT` -->
195+
<!--
196+
the following dependency versions are specified to resolve dependency tree conflicts
197+
- see also exclusions in `maven-enforcer-plugin`
198+
- see `docs/dependency_conflicts.md` for more info
199+
-->
200+
201+
<!-- resolve conflict between `org.jlab.jnp:jnp-hipo:jar:2.0-SNAPSHOT` and `org.jlab.jnp:jnp-hipo4:jar:4.3-SNAPSHOT`
202+
by choosing the later version of their `net.objecthunter:exp4j` dependency -->
203+
<dependency>
180204
<groupId>net.objecthunter</groupId>
181205
<artifactId>exp4j</artifactId>
182-
<version>0.4.8</version> <!-- choose the later version -->
206+
<version>0.4.8</version> <!-- WARNING: if changed, see `docs/dependency_conflicts.md` -->
183207
</dependency>
184208

185-
<dependency> <!-- resolve conflict between `org.jlab.coda:jclara` and `ai.djl:api` -->
209+
<!-- resolve conflict between `org.jlab.coda:jclara` and `ai.djl:api`
210+
by choosing the later version of their `com.google.code.gson:gson` dependency -->
211+
<dependency>
186212
<groupId>com.google.code.gson</groupId>
187213
<artifactId>gson</artifactId>
188-
<version>2.13.1</version> <!-- choose the later version -->
214+
<version>2.13.1</version> <!-- WARNING: if changed, see `docs/dependency_conflicts.md` -->
189215
</dependency>
190216

191-
<dependency> <!-- resolve conflict between `j4ml:j4ml-clas12` and `clas-tracking` -->
217+
<!-- resolve conflict between `j4ml:j4ml-clas12` and `clas-tracking`
218+
by using the version of `org.ejml:ejml-simple` used by `j4ml:j4ml-clas12:jar:0.9-SNAPSHOT` -->
219+
<dependency>
192220
<groupId>org.ejml</groupId>
193221
<artifactId>ejml-simple</artifactId>
194-
<version>0.40</version> <!-- match version from `j4ml:j4ml-clas12:jar:0.9-SNAPSHOT` -->
222+
<version>0.40</version> <!-- WARNING: if changed, see `docs/dependency_conflicts.md` -->
195223
</dependency>
196224

197225
<!-- END DEPENDENCY CONFLICT RESOLUTION -->

reconstruction/mltn/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@
2323
<dependency>
2424
<groupId>j4ml</groupId>
2525
<artifactId>j4ml-neuroph</artifactId>
26-
<version>0.9-SNAPSHOT</version>
2726
</dependency>
2827

2928
<dependency>
3029
<groupId>j4ml</groupId>
3130
<artifactId>j4ml-data</artifactId>
32-
<version>0.9-SNAPSHOT</version>
3331
</dependency>
3432

3533
<dependency>
3634
<groupId>j4ml</groupId>
3735
<artifactId>j4ml-clas12</artifactId>
38-
<version>0.9-SNAPSHOT</version>
3936
</dependency>
4037

4138
<dependency>

0 commit comments

Comments
 (0)