Maven - 添加对工件源的依赖 [英] Maven - add dependency on artifact source

查看:22
本文介绍了Maven - 添加对工件源的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 maven 模块,一个以 jar 的形式结束,一个 war 依赖于该 jar.

I have two maven modules, one that ends up as a jar, and one war that depends on that jar.

我希望 jar 模块将它的源代码与 jar 中的已编译类一起打包,以便第二个模块能够访问它.我曾尝试使用 maven-source-plugin,但我对如何添加对其输出的依赖感到困惑.似乎默认情况下依赖项转到编译的 jar,而不是 maven-source-plugin 创建的源代码 jar(以-source.jar"结尾).

I want the jar module to package it's source code together with the compiled classes in the jar, so that the second module is able to access it. I have tried using the maven-source-plugin, but I am confused as to how to add a dependency on the output of that. It seems that the dependency by default goes to the compiled jar, and not the source-code jar (ending with "-source.jar") that maven-source-plugin creates.

如何将-source.jar"添加为依赖项,同时仍保留对已编译源的依赖项?

How do I add the "-source.jar" as a dependency, while still preserving the dependency on the compiled sources?

推荐答案

这个我没试过,但是我认为你需要在你的项目中创建两个配置文件.一个构建主罐子.另一个构建源jar.不幸的是,我不确定您将如何构建该配置文件.到目前为止,我找不到一个很好的例子.

I've not tried this, but I think you need to create two profiles in your project. One which builds the main jar. The other which builds the sources jar. Unfortunately, I'm not exactly sure how you would build that profile. I couldn't find a good example of it so far.

(根据评论,您实际上并不需要配置文件.您只需使用将部署源并通过源分类器使它们可用的源插件)

(Accoding to the comments, you don't actually need a profile. You can just use the sources-plugin which will deploy the sources and make them available via the sources classifier)

理论上,您可以使用第二个配置文件将源附加到项目中.这会在您的存储库中为使用该分类器的源创建第二个条目.将源安装/部署到存储库后,您应该能够通过使用依赖项上的分类器标记直接指定源来将源包含为依赖项.

In theory, you'd use the 2nd profile to attach the sources to the project. This creates a 2nd entry in your repository for the sources using that classifier. Once you install/deploy the sources to your repository, you should be able to include the sources as a dependency by using the classifier tag on the dependency to specify the sources directly.

所以你的 webapp POM 中会有这样的东西:

So you'd have something like this in your webapp POM:

<dependencies>
  <dependency>
    <groupId>myGroup</groupId>
    <artifactId>myJar</artifactId>
    <version>4.0</version>
    <type>jar</type>
  </dependency>
  <dependency>
    <groupId>myGroup</groupId>
    <artifactId>myJar</artifactId>
    <version>4.0</version>
    <type>jar</type>
    <classifier>sources</classifier>
  </dependency>
</dependencies>

这篇关于Maven - 添加对工件源的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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