Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,17 @@ static ImmutableMap<String, String> findLocalArtifacts(
artifactToVersion.put(versionlessCoordinates, model.getVersion());
logger.fine("Found local artifact: " + model);
DependencyManagement dependencyManagement = model.getDependencyManagement();
if ("pom".equals(model.getPackaging()) && dependencyManagement != null) {
// Read the content of a BOM.

// For gax-java repository (Gradle), the dependencyManagement section of the gax-bom/pom.xml
// tells what artifacts the repository produces. However, we have to distinguish BOMs from
// normal parent poms
// (https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/1958).
// Unfortunately the difference between a BOM and a parent POM is how we name it. Therefore
// this logic checks whether the artifactId of the pom.xml files has "-bom" or not.
if (model.getArtifactId().endsWith("-bom")
&& "pom".equals(model.getPackaging())
&& dependencyManagement != null) {
// Read the dependencyManagement section of a BOM.
for (org.apache.maven.model.Dependency dependency :
dependencyManagement.getDependencies()) {
String managedDependencyVersionlessCoordinates =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public void testFindLocalArtifacts() {

// This should not include project under "build" directory, but should include the entries
// in the dependencyManagement section of the gax-bom/pom.xml.
// This should not include the grpc-google-cloud-pubsub-v1 in the root testproject pom.xml
Truth.assertThat(localArtifacts).hasSize(6);
assertEquals("0.0.1-SNAPSHOT", localArtifacts.get("com.google.cloud.tools:test-project"));
assertEquals("0.0.2-SNAPSHOT", localArtifacts.get("com.google.cloud.tools:test-subproject"));
Expand All @@ -287,6 +288,10 @@ public void testFindLocalArtifacts() {
"localArtifacts should contain the dependency management section in the BOM",
"1.60.2-SNAPSHOT",
localArtifacts.get("com.google.api:gax"));

// localArtifacts should not include the dependencyManagement section of a non-BOM pom.xml
Truth.assertThat(localArtifacts)
.doesNotContainKey("com.google.api.grpc:grpc-google-cloud-pubsub-v1");
}

@Test
Expand Down
9 changes: 9 additions & 0 deletions linkage-monitor/src/test/resources/testproject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@

<name>Test Project for LinkageMonitorTest</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-pubsub-v1</artifactId>
<version>1.93.1</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>