java - 如何解决 Maven 提供的范围问题
问题描述
我正在构建一个自定义声纳插件,它是一个 Maven 项目。
Sonar 要求提及它sonar-plugin-api
作为 scope 的必需依赖项provided
。我认为这没关系,因为它会在装有这个 jar 的声纳容器内运行。
在我的用例中,我想添加httpclient
. 如果我在默认范围内添加它,它会拒绝构建,并抛出以下错误:
[ERROR] This dependency must be declared with scope <provided>: commons-logging:commons-logging:jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.364 s
[INFO] Finished at: 2019-03-05T13:52:22+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.sonar-packaging-maven-plugin:sonar-packaging-maven-plugin:1.18.0.372:check (default-check) on project myPlugin: Unsupported dependencies
如果我将范围更改httpclient
为provided
,它将构建但不会在声纳中工作,因为它的环境中没有这个 jar。
中的所有依赖项httpclient
,包括commons-logging
被称为范围 - compile
。
这是我当前的 pom 的样子:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.plugin.sonar</groupId>
<artifactId>myPlugin</artifactId>
<!-- this is important for sonar-packaging-maven-plugin -->
<packaging>sonar-plugin</packaging>
<version>1.0</version>
<name>myPlugin</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<!-- minimal version of SonarQube to support. Note that the groupId was "org.codehaus.sonar" before version 5.2 -->
<version>6.7</version>
<!-- mandatory scope -->
<scope>provided</scope>
</dependency>
<!-- facing problem after adding this dependency-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.18.0.372</version>
<extensions>true</extensions>
<configuration>
<pluginKey>MyCustomPlugin</pluginKey>
<pluginClass>com.plugin.sonar.MyCustomPlugin</pluginClass>
<pluginDescription>Sonar plugin of Test</pluginDescription>
</configuration>
</plugin>
</plugins>
</build>
</project>
任何建议,如何解决?
谢谢你
解决方案
Sonar Maven 插件包含一个不允许 commons-logging 和 LOG4J 的检查,因为 SonarQube 仅支持 SLF4J。
所以你可以做的是切换到 SLF4J 并commons-logging
从httpclient
依赖项中排除:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.26</version>
</dependency>
推荐阅读
- spring-boot - 从不同的微服务读取相同的缓存
- angular - 如何从组件执行功能(
- google-api - 有没有办法使用 Google Drive API 下载大于 10MB 的文档?
- node.js - 使用nodejs在firebase中列出GCP Bucket对象
- java - 春季时区问题中的 DateTimeFormat 注释
- php - Codeigniter:如何更改结果数组
- python - 从列表中删除以某些表达式开头的字符串
- c++ - vkCmdCopyBuffer 对暂存缓冲区的传输没有影响
- r - R使用group_by中的pracma pkg中的movavg()和summarise()计算加权移动平均值?
- c - C - 如何初始化一个未知大小的二维数组