Maven - Add jar-with-dependencies as a dependency

后端 未结 2 688
夕颜
夕颜 2021-02-13 03:40

Question..
I\'d like to add a dependency on a Maven jar packaged with it\'s dependencies.

Details..
I have a multi-mod

相关标签:
2条回答
  • 2021-02-13 04:04

    You can do this with a maven classifier. Classfiers are used so a maven module can build multiple artefacts from the same source. Examples are jdk1.6 or 1.7 version or even the source and javadoc jars maven can build.

    So try this:

    <dependency>
      <groupId>yourID</groupId>
      <artifactId>seaniscool</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <classifier>jar-with-dependencies</classifier>
    </dependency>
    

    If you want to rename your classfier to a better name like withNative or complete or anything else have a look at the maven shade plugin which can also build jars with dependencies but allows some more control.

    0 讨论(0)
  • 2021-02-13 04:11

    Just a side note to @msczalbach's answer

    Actually, even with standarad maven-jar-plugin you can give any suffix to generated jar. Just use the configuration.

    E.g:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
    </plugin>
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <descriptorRefs>
                <descriptorRef>self-contained</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>
    
    0 讨论(0)
提交回复
热议问题