有以下幾種方法可以排除Maven依賴項的傳遞性依賴:
<dependency>
<groupId>com.example</groupId>
<artifactId>example-artifact</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>org.transitive.dependency</groupId>
<artifactId>transitive-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-artifact</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-artifact</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>org.transitive.dependency</groupId>
<artifactId>transitive-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
通過以上方法,可以有效地排除Maven依賴項的傳遞性依賴,確保項目的依賴項管理更加清晰和可控。