仅使用maven部署一些依赖项 [英] Deploying only some of the dependencies with maven
问题描述
我有一个问题,我不知道如何妥善解决它。我正在为一个在启动时动态加载这些插件的程序开发插件。一切都很顺利,因为我通常只使用像主要程序使用的Apache Commons这样的依赖项。
I have a problem that I do not know how solve it properly. I'm developing plugins for a program that loads these plugins dynamically on start up. Everything worked out very well so far as I usually only do use dependencies like Apache Commons which have been used by the main program, too.
现在我试着玩Google Guice和主程序在类路径中没有包,因此启动时会出现NoClassDefFoundError。我使用谷歌一段时间来找到解决我的问题的方法但我唯一想到的就是使用超级罐。问题是,我确实依赖于我使用的其他插件,我不想将它们插入到我的插件中,因为我最终必须管理所有插件。甚至可能发生我在类路径中有两个不同的实现,因为我丢失了跟踪并且没有更新那个次要版本。不幸的是,通常没有其他插件的接口,所以我不能接受它。
Now I tried to play around with Google Guice and the main program does not have the package in the class path and so there is a NoClassDefFoundError at start up of course. I used google for a while to find a solution to my problem but the only thing I came up with was using an uber jar. The problem with that is, that I do have dependencies to other plugins that I use and I don't want to pull them in my plugin as I would end up having to manage all of them. It might even happen that I have two different implementations in the class path because I lost track and did not update that minor version. Unfortunately there is usually no interface for other plugins so I cannot take that in.
长文本,简短的问题:是否有可能告诉Maven只在文件中拉Guice或者,更好的是,这个问题是否有更清洁的解决方案?也许我甚至错过了整个过程中至关重要的事情?任何帮助都表示赞赏。
Long text, short question: is it possible to tell Maven to only pull Guice in the file or, even better, is there a cleaner solution to this problem? Maybe I even did miss something crucial in the whole process? Any help is appreciated.
推荐答案
我刚刚找到了一个有效的解决方案。使用这样的阴影插件可以得到所需的结果:
I just found a solution that works. Using the shade plugin like this yields the needed results:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.google.inject:guice</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
这篇关于仅使用maven部署一些依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!