[英]Maven - dependency conflict with Spark and HtmlUnit
我想结合HtmlUnit使用“spark”Web框架(Java中的sinatra克隆)。
我的想法是,我的WebService将能够下载网站并解析它们(并执行JavaScripts等),然后收集一些数据,做一些统计等.HtmlUnit不仅用于测试,而且实际上需要在主项目中。
无论如何,Spark在Jetty上运行,Spark和HtmlUnit似乎都使用相同的websocket客户端库( org.eclipse.jetty.websocket:websocket-client:9.3.2.v20150730
),但版本不同。 还有一些其他库似乎会产生问题。
项目编译良好,但无法启动Web服务器。
有办法以某种方式解决这些冲突吗?
这是我的依赖项:
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-template-freemarker</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
我还找到了强制插件,列出了所有冲突。 这是输出:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for org.slf4j:slf4j-api:1.7.12 paths to dependency are:
+-com.example:helloworld:1.0-SNAPSHOT
+-com.sparkjava:spark-core:2.3
+-org.slf4j:slf4j-api:1.7.12
and
+-com.example:helloworld:1.0-SNAPSHOT
+-com.sparkjava:spark-core:2.3
+-org.slf4j:slf4j-simple:1.7.12
+-org.slf4j:slf4j-api:1.7.12
and
+-com.example:helloworld:1.0-SNAPSHOT
+-com.sparkjava:spark-template-freemarker:2.0.0
+-org.slf4j:slf4j-api:1.7.2
,
Dependency convergence error for commons-codec:commons-codec:1.9 paths to dependency are:
+-com.example:helloworld:1.0-SNAPSHOT
+-net.sourceforge.htmlunit:htmlunit:2.19
+-org.apache.httpcomponents:httpclient:4.5.1
+-commons-codec:commons-codec:1.9
and
+-com.example:helloworld:1.0-SNAPSHOT
+-net.sourceforge.htmlunit:htmlunit:2.19
+-commons-codec:commons-codec:1.10
,
Dependency convergence error for xml-apis:xml-apis:1.3.04 paths to dependency are:
+-com.example:helloworld:1.0-SNAPSHOT
+-net.sourceforge.htmlunit:htmlunit:2.19
+-xalan:xalan:2.7.2
+-xalan:serializer:2.7.2
+-xml-apis:xml-apis:1.3.04
and
+-com.example:helloworld:1.0-SNAPSHOT
+-net.sourceforge.htmlunit:htmlunit:2.19
+-xerces:xercesImpl:2.11.0
+-xml-apis:xml-apis:1.4.01
,
Dependency convergence error for org.eclipse.jetty.websocket:websocket-client:9.3.2.v20150730 paths to dependency are:
+-com.example:helloworld:1.0-SNAPSHOT
+-com.sparkjava:spark-core:2.3
+-org.eclipse.jetty.websocket:websocket-server:9.3.2.v20150730
+-org.eclipse.jetty.websocket:websocket-client:9.3.2.v20150730
and
+-com.example:helloworld:1.0-SNAPSHOT
+-net.sourceforge.htmlunit:htmlunit:2.19
+-org.eclipse.jetty.websocket:websocket-client:9.2.13.v20150730
,
Dependency convergence error for com.sparkjava:spark-core:2.3 paths to dependency are:
+-com.example:helloworld:1.0-SNAPSHOT
+-com.sparkjava:spark-core:2.3
and
+-com.example:helloworld:1.0-SNAPSHOT
+-com.sparkjava:spark-template-freemarker:2.0.0
+-com.sparkjava:spark-core:2.0.0
]
排除在所有地方创建冲突的依赖项,除了这样的:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.3</version>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
在任何需要的地方添加其他排除项
编辑:我创建了测试应用程序与您列出的依赖项,我认为这可能会有效
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.3</version>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>websocket-server</artifactId>
<groupId>org.eclipse.jetty.websocket</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-template-freemarker</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>spark-core</artifactId>
<groupId>com.sparkjava</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
<exclusions>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>xalan</artifactId>
<groupId>xalan</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
可以使用第二件事情是<dependencyManagement>
在POM的根(相同的水平<dependencies>
你迄今使用)。 在dependencyManagement中,您可以指定将使用哪个库的版本,如下所示:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</dependencyManagement>
这样,无论哪个版本的库foo:bar
包含在任何依赖项中,都将始终使用版本1.2.3。
我有完全相同的问题,我能够通过将htmlunit和sparkjava的所有常见依赖项设置为相同的版本来解决它,如下所示:
请注意,我使用的是最新版本。
<!-- Spark framework to create restful endpoints -->
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5.4</version>
</dependency>
<!-- HTMLUnit for crawling purposes -->
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.23</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.3.6.v20151106</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.3.6.v20151106</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.3.6.v20151106</version>
</dependency>
</dependencies>
</dependencyManagement>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.