Maven的新功能:使用阴影插件和第三方罐子 [英] New at Maven: Using the shade plugin and 3rd party jars

查看:127
本文介绍了Maven的新功能:使用阴影插件和第三方罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很简单,但我无法绕过它。我需要使用第三方罐子创建一个uberjar。我已经按照这些说明操作了:包括非Mavenized依赖项,以便它与maven-shade-plugin 一起使用并将它们添加到本地存储库。但现在呢?每个Maven教程/示例都有点阴暗(双关语),我只是不知道如何正确编辑.pom文件以使其工作。

This should be pretty simple, but I can't the around to it. I need to create an uberjar using 3rd party jars. I've already followed these instructions: Including a non-Mavenized dependency so it works with maven-shade-plugin and added them to the local repository. But now what? Every Maven tutorial/example is kinda shady (pun intended) and I just don't know how to edit the .pom file properly in order to make it work.

此外,我对整个阴影插件感到困惑。我的意思是,我遵循了基本的Maven教程,它一切都很好,花花公子。但是当我查看shade插件页面时,除了源代码之外我找不到要下载的内容。我的意思是,这不是一个插件吗?我不应该下载二进制文件并以某种方式将它安装到Maven中吗?

Besides, I'm confused about the shade "plugin" overall. I mean, I followed the basic Maven tutorials and it went all fine and dandy. But when I look into the shade plugin page, I can't find it to download, except for the source code. I mean, isn't it a plugin? Shouldn't I download the binaries and install it into Maven somehow?

对于极端的noobish问题感到抱歉,但不用说,我知道对Maven的蹲坐。

Sorry about the extreme noobish question but, needless to say, I know squat about Maven.

推荐答案

要创建着色(超级)jar,只需要在 pom.xml中声明shade插件

To create your shaded (uber) jar, you just need to declare the shade plugin in your pom.xml.

关于安装阴影插件,只需在插件中声明 pom.xml 的部分就是你需要做的。 Maven插件不是手动安装的,而是由Maven自动下载(如果尚未下载;就像依赖项一样),存储在本地存储库中,并在项目需要时使用。

With regards to installation of the shade plugin, simply declaring it in the plugins section of your pom.xml is all you need do. Maven plugins are not installed manually, but are automatically downloaded by Maven (if not already downloaded; just like dependencies), stored in your local repository, and used whenever a project needs them.

关于使用它,就像其他插件一样,通过添加< plugin> pom.xml 中声明它$ c>元素满足您的配置需求。这个插件什么都不做(有些做,有些不做) - 你必须指定要执行的目标(想想类的方法),以及阶段(想想构建过程的步骤) )。除非你有奇怪的需求,否则在包阶段指定阴影目标(见下文)。

As to using it, much like other plugins, declare it in your pom.xml by adding a <plugin> element with your configuration needs. This plugin does nothing automatically (some do, some don't) - you have to specify which "goal" to execute (think "method of a class"), and in which "phase" (think "step" of the build process). Unless you have strange needs, specify the "shade" goal in the "package" phase (see below).

有关更多配置可能性,请参阅阴影使用情况页面及其示例(尤其是选择超级罐的内容)。这是一个简单的示例,当您运行 mvn package 时,将 target / 目录中的原始jar替换为超级罐子。它只包含运行时依赖项,而不是测试时使用的依赖项(注意junit依赖项的< scope> 元素,它不包含在uber jar中)。

For more configuration possibilities, see the shade usage page, and their examples (especially selecting contents for uber jar). Here is a simple example which, when you run mvn package, replaces your original jar in the target/ directory with the uber jar. It only includes the runtime dependencies, not the ones used at test time (notice the <scope> element of the junit dependency, which is not included in the uber jar).

<project>
  <groupId>com.sample</groupId>
  <artifactId>test</artifactId>
  <version>1.0</version>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.sample</groupId>
      <artifactId>test-core</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

这篇关于Maven的新功能:使用阴影插件和第三方罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆