我想將「spark」web框架(Java中的sinatra克隆)與HtmlUnit結合使用。Maven - 與Spark和HtmlUnit的依賴衝突
這個想法是,我的WebService將能夠下載網站和解析它們(並執行JavaScript等),然後收集一些數據,做一些統計等。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
]
好的,我會試試這個。 – Peanut
它看起來像火花核心和HtmlUnit似乎使用相同的類文件,似乎是衝突(Websocket似乎是罪魁禍首)。火花核心版本和使用相同版本的HtmlUnit版本沒有組合 – Peanut
您是否試過從HtmlUnit中排除org.eclipse.jetty.websocket:websocket-client? –