Maven jar依赖关系 [英] Maven jar dependencies and relations

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

问题描述

我试图搜索现有的问题,但找不到任何东西 - 感觉我的问题很简单,但可能是因为它是非常具体的,我无法找到任何地方。

I tried to search for existing questions but cant find any - feels like my question is quite simple but probably because it's quite specific I cant find the answers anywhere.

无论如何 - 我有两个项目与Maven,其中第二个依赖/需要一些类的第一个。在某些情况下,我希望依赖关系在JAR上而不是项目依赖。

Anyways - I have 2 projects with Maven where the second depends on/needs some classes of the first. In certain cases I want the dependency to be on the JAR rather than a project dependency.

我通过使用maven-jar-plugin创建一个附加的jar来解决这个问题,其中i包括所需的类。该jar已正确创建,并在$ {project.build.directory}中输出。但项目A的pom位于同一个目录中,这对我来说是一个痛苦,对于项目B,是项目A中使用的依赖关系的原因。
(有没有办法忽略位于$ {project.build.directory}?like:

I solved this by creating an additional jar with maven-jar-plugin, where i included the needed classes. The jar was correctly created and was output in ${project.build.directory}. But the pom of project A is located in the same directory, that is/was a pain for me and for project B, cause of the dependencies used in project A. (is there a way to ignore the pom located in ${project.build.directory} ??? like:

<dependency>
            <groupId>projectA.groupId</groupId>
            <artifactId>A</artifactId>
            <version>1x-SNAPSHOT</version>
            <classifier>classes</classifier>
                    ->  <ignorePom>true</ignorePom>
        </dependency>



< >)。

).

现在我使用系统范围的依赖关系,并在添加系统路径后工作正常。尽管范围系统必须在任何地方都可以避免。
Systempath令我烦恼,因为这不是一个好习惯,而是因为绝对路径。

Now I´m using the system scope for the dependency and its working fine after adding the systempath. Although the scope system must be avoided everywhere it is possible. The Systempath is annoying me because this is not a good practice and because of the absolute path.

我知道我可以将创建的jar安装到存储库通过使用

I know that i can install the created jar into the repository by using


mvn install:install -file

mvn install:install -file



but i want to automate this process as good as possible, what would you suggest?

提前感谢

推荐答案

最好的解决方案是使用存储库管理器,并且做一个真正的第一个jar的发行版,并在需要的地方做一个真正的依赖。

The best solution is to use a repository manager and do a real release of the first jar and make a real dependency where you need.

根据你写的内容,我会建议创建一个单独的maven项目,其中包含几个其他模块将被使用的类,释放它,只需使用对该模块的依赖。这将彻底解决您的问题。

Based on what you wrote i would recommend to create a separate maven project which contains the classes which will be used by several other modules make a release of it and simply use a dependency on that module. This will solve your problem completely.

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

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