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

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

问题描述

我有两个maven模块,一个最终作为一个jar,一个战争取决于那个jar。



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



如何添加-source.jar作为依赖关系,同时仍保留对编译源的依赖性?

解决方案

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



(对于评论,你实际上并不需要一个配置文件,你可以使用source-插件将部署源代码并通过源分类器使其可用)



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



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

 <依赖关系> 
<依赖关系>
< groupId> myGroup< / groupId>
< artifactId> myJar< / artifactId>
< version> 4.0< / version>
< type> jar< / type>
< / dependency>
<依赖关系>
< groupId> myGroup< / groupId>
< artifactId> myJar< / artifactId>
< version> 4.0< / version>
< type> jar< / type>
< classifier> sources< / classifier>
< / dependency>
< / dependencies>


I have two maven modules, one that ends up as a jar, and one war that depends on that 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.

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

解决方案

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.

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 - 添加对artifact源的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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