maven-assembly-plugin doesn't add dependencies with system scope

梦想的初衷 提交于 2019-11-27 09:12:52
Pascal Thivent

Yes, and this is one of the reasons you shouldn't abuse system scope dependencies (which is globally a bad practice) and this problem has already been mentioned several times here on SO (here, here). I'm proposing a solution to deal with project relative dependencies in a "clean" way in this answer.

you can do it by adding this dependencySet to your assembly file descriptor

<dependencySet>
    <outputDirectory>/</outputDirectory>
    <unpack>true</unpack>
    <scope>system</scope>
</dependencySet>

this assembly descriptor add all dependencies including system scoped

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-all-dependencies</id>
<formats>
    <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <useProjectArtifact>true</useProjectArtifact>
        <unpack>true</unpack>
        <scope>runtime</scope>
    </dependencySet>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <unpack>true</unpack>
        <scope>system</scope>
    </dependencySet>
</dependencySets>

 </assembly>

You should remove the <scope>system</scope> clauses from those dependencies. When the scope is set to system that means the artifact is ALWAYS available, so jar-with-dependencies does not include it.

It must not be system scope in the first place. This is the source of your problem. Install/deploy your dependency into the repository and make it a normal compile (or runtime) scope dependency.

Unpack your jar and add it to src/main/resources.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!