创建一个包含依赖关系管理maven的jar [英] Create a jar that contain dependency management maven

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

问题描述

我已经创建了一个包含一些常见jar的jar,我们将在不同的应用程序中使用它,并且可以被许多用户使用。

I already create a jar that contain some common jars, which we will use it in different applications and can be used via many users.

要解决这个问题,我创建一个普通的jar,所以我可以控制这个公共罐子和它们的版本,然后将它存储在nexus服务器中,因此它可以包含父pom并且可以被许多开发人员使用。

To Solve this, i create a common jars, so i can control this commons jars and version of them, then store it in nexus server, so it can contain the parent pom and can be used by many developers.

所以我创建了一个简单的maven java应用程序,在这个jar的pom中,我举了例子:

So i create a simple maven java application and in the pom of this jar, i put for example :

父pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.emp</groupId>
    <artifactId>dependencymanager</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.primefaces</groupId>
                <artifactId>primefaces</artifactId>
                <version>6.0</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>javax.persistence</artifactId>
                <version>2.1.1</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

然后在子应用程序中我使用这样的jar:

Then in the child applications i use this jar like this:

<dependencies>
    <dependency>
        <groupId>com.emp</groupId>
        <artifactId>dependencymanager</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

但是当我尝试使用 org.primefaces ,我不能。哪里我错了,或者我在实施依赖管理方面错了?

But when i try to use org.primefaces, i can't. Where i'm wrong, or i'm wrong in the implementation of dependency management?

注意

我已经读过这个: http:/ /maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

因此,在本教程的示例中,它没有指定父pom的版本,所以当我删除它时显示如下错误:

So in the example of this tutorial it not specify the version of the parent pom, so when i delete it show me an error like this :

'dependencies.dependency.version' for com.emp:dependencymanager:jar is missing.

问题


  • 在这种情况下如何实现依赖关系管理?

  • 有没有更好的方法可以使用
    许多项目和许多开发人员来处理相同的依赖关系。

  • 我使用nexus存储我的罐子

谢谢。

推荐答案

在父pom中,直接添加依赖项,省略 dependencyManagement 标记。使用 dependencyManagement ,您只需指定如果在您的pom中声明了这样的依赖关系,那么将使用父pom中指定的版本。但是你的父pom本身并不包含那些作为传递依赖的依赖。

In the parent pom, add the dependencies directly, leaving out the dependencyManagement tags. With the dependencyManagement you only specify that if such a dependency is declared in your pom, that the version specified in the parent pom is to be used. But your parent pom does not per se include those dependencies as transitive dependencies.

这篇关于创建一个包含依赖关系管理maven的jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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