【问题标题】:Can't override a maven dependency from third party lib -NiFi无法覆盖来自第三方库 -NiFi 的 Maven 依赖项
【发布时间】:2017-10-27 22:31:16
【问题描述】:

我一直致力于创建自定义 NIFI 处理器。我正在尝试使用使用 Lucene 6.5.0 的 luwak 搜索库。但是,NiFi 库似乎使用 Lucene 4.10.4。我已经用 pom 文件尝试了各种各样的东西,但是在我构建 nar 文件时无法让它覆盖 NiFi 4.10.4 lib。这很可能是用户错误。我只是无法为我的生活弄清楚它是什么。在我的 IDE 中运行良好,但是当我构建工件 (NAR) 时,我可以看到 4.10.4 库在那里,但不是 Luwak 需要的一些 6.5.0。任何帮助将不胜感激。

阅读研究表明,如果我专门将我需要的库的 Lucene 版本放在带有 DependencyMangement 的 pom 中,它就会起作用。还尝试了排除(也显示)。

已编辑:尝试了@Rob 的建议并删除了 pom 进口。但是,仍然有同样的问题。更新 Pom 示例

Maven 依赖树:

    [INFO] gov.pnnl.nifi:nifi-streamqry-nar:nar:1.3
[INFO] \- gov.pnnl.nifi:nifi-streamqry-processors:jar:1.3:compile
[INFO]    \- com.github.flaxsearch:luwak:jar:1.5.0:compile
[INFO]       +- org.apache.lucene:lucene-core:jar:4.10.4:compile (version managed from 6.5.0)
[INFO]       +- org.apache.lucene:lucene-memory:jar:6.5.0:compile
[INFO]       |  \- (org.apache.lucene:lucene-core:jar:4.10.4:compile - version managed from 6.5.0; omitted for duplicate)
[INFO]       +- org.apache.lucene:lucene-analyzers-common:jar:4.10.4:compile (version managed from 6.5.0)
[INFO]       |  \- (org.apache.lucene:lucene-core:jar:4.10.4:compile - version managed from 6.5.0; omitted for duplicate)
[INFO]       +- org.apache.lucene:lucene-queries:jar:6.5.0:compile
[INFO]       |  \- (org.apache.lucene:lucene-core:jar:4.10.4:compile - version managed from 6.5.0; omitted for duplicate)
[INFO]       \- org.apache.lucene:lucene-queryparser:jar:4.10.4:compile (version managed from 6.5.0)
[INFO]          \- (org.apache.lucene:lucene-core:jar:4.10.4:compile - version managed from 6.5.0; omitted for duplicate)

POM 文件

<properties>
    <lucene.group>org.apache.lucene</lucene.group>
    <lucene.version>6.5.0</lucene.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>${lucene.group}</groupId>
            <artifactId>lucene-core</artifactId>
            <version>6.5.0</version>
        </dependency>
        <dependency>
            <groupId>${lucene.group}</groupId>
            <artifactId>lucene-memory</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>${lucene.group}</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-queries -->

        <dependency>
            <groupId>${lucene.group}</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>${lucene.group}</groupId>
            <artifactId>lucene-queries</artifactId>
            <version>${lucene.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-api</artifactId>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-queryparser</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-utils</artifactId>
        <exclusions>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-queryparser</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-mock</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-queryparser</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-sandbox</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

排除:

<dependencies>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-api</artifactId>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-queryparser</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-utils</artifactId>
        <exclusions>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-queryparser</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-mock</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-queryparser</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
            </exclusion>
            <exclusion>
                <groupId>${lucene.group}</groupId>
                <artifactId>lucene-sandbox</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>

【问题讨论】:

  • 你试过从第三方库依赖中排除它吗?
  • 高 @Stultuske 我确实试过了。也许我做错了。

标签: java maven lucene apache-nifi


【解决方案1】:

4.x lucene 版本不是通过传递依赖进入的,因此将它们排除在 nifi-api 和 nifi-mock 之类的东西之外不会做任何事情。

您获得 4.x 版本的原因是因为您的 NAR 捆绑根 pom 很可能具有 nifi-nar-bundles 的父级,这意味着您一直继承到 NiFi 的根 pom,这导致了 NiFi 的依赖管理在您的 NAR 中生效。

你有两个选择...

1) 如果这是一个将在 NiFi 源代码树之外存在的自定义捆绑包,那么您可以删除捆绑包和 NiFi 之间的这种关系。此处对此进行了描述:

https://cwiki.apache.org/confluence/display/NIFI/Maven+Projects+for+Extensions#MavenProjectsforExtensions-Inheritance

最新的 NAR 插件是 1.2.0。

2) 如果您打算将其贡献回 NiFi,或者如果您正在维护自己的 NiFi 分支并希望您的捆绑包存在于 nifi/nifi-nar-bundles 下,那么您应该能够完成这项工作通过在包的根 pom 中声明您自己的 dependencyManagement 部分,并声明与顶级 NiFi pom 中相同的 lucene 依赖项,并将其版本设置为 6.5.0。

在 NiFi 中已经有一些类似情况的例子了..

例如NiFi的顶级pom声明了特定版本的http-client,而Solr处理器需要不同的版本,所以在这里重新声明:

https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-solr-bundle/pom.xml#L43-L45

第二个选项的重要部分是您的 dependencyManagement 部分必须位于位于处理器和 NAR 之上的包的 pom 中。

【讨论】:

  • 太棒了。谢谢@Bryan Bende,我会看看。非常感谢您提供的信息。
【解决方案2】:

你的问题是由

引起的
<type>pom</type>
<scope>import</scope>

来自Maven documentation

import(仅在 Maven 2.0.9 或更高版本中可用)此范围仅 支持 pom 类型的依赖项 部分。它表示要替换为有效的依赖项 指定 POM 中的依赖项列表 部分。由于它们已被替换,因此具有导入范围的依赖项 实际上并不参与限制 a 的传递性 依赖。

您几乎肯定希望使用 jar 工件。如果您只需删除 and 标签,它可能会按照您的意愿工作。

通过明确提及具有特定版本的组/工件,maven 将更喜欢该版本而不是通过传递依赖项包含的那些版本。只要组/工件名称没有改变,那么这种方法就可以很好地工作。

但是,如果组/工件名称已更改,您将需要排除标记中拉入过时工件的依赖项。

【讨论】:

  • 嗨@Rob。感谢您的回复。我取出了所有的 pom / import 引用并进行了重建。我仍然在依赖树中看到相同的输出。还有其他想法吗? [INFO] \- gov.pnnl.nifi:nifi-streamqry-processors:jar:1.3:compile [INFO] \- com.github.flaxsearch:luwak:jar:1.5.0:compile [INFO] +- org.apache .lucene:lucene-core:jar:4.10.4:compile(从 6.5.0 管理的版本)
猜你喜欢
  • 1970-01-01
  • 2017-01-13
  • 1970-01-01
  • 2015-01-06
  • 2011-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-10
相关资源
最近更新 更多