管理外部依赖的多个版本

问题描述 投票:0回答:1

我正在尝试创建我的自定义 nifi 控制器服务。为此,我必须在 eclipse 中基于 nifi-service-bundle-archetype 创建 Maven 项目。这样做时,会创建以下结构:

-Project 
-- ContollerService
---pom.xml 

-- ContollerService-api
---pom.xml           

-- ContollerService-api-nar
---pom.xml 

-- ContollerService-nar
---pom.xml 

-pom.xml

项目除了子模块之外还有自己的pom.xml,每个子模块都有自己的pom.xml

项目 pom.xml 如下所示:

<project ...>
    <modelVersion>4.0.0</modelVersion>
    
    
    <parent>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-nar-bundles</artifactId>
        <version>1.16.0</version>
    </parent>
    
  

    <groupId>nifi</groupId>
    <artifactId>ContollerService</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <modules>
        <module>ContollerService-api</module>
        <module>ContollerService-api-nar</module>
        <module>ContollerService</module>
        <module>ContollerService-nar</module>
    </modules>

</project>

子模块依赖于不同的nifi包。

我面临的问题是我试图为两个不同的 nifi 版本 1.16.0 和 2.0.0-M3 创建两个不同的版本。我的问题是,考虑到以下限制,我可以在同一项目中管理两个不同的 nifi 版本的最佳方法是什么:

1- nifi 版本 1.16 使用 java 1.8,而 2.0.0-M3 使用 java 21。

2-在项目pom中,当nifi版本为1.16时,父级是:

<parent>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-nar-bundles</artifactId>
        <version>1.16.0</version>
    </parent>

但是对于版本 2.0.0M3 使用不同的父包:

  <parent>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-extension-bundles</artifactId>
        <version>2.0.0-M3</version>
    </parent>

我的目标是在同一个 Maven 项目下针对不同版本创建不同的 Maven 构建,这将处理以下内容:

1-将正确的包(具有正确的版本)应用到项目pom。

2-在每个子模块中应用正确的 nifi 依赖版本。

3-应用正确的 java 构建(如果我必须创建不同的构建配置文件来处理这个问题,没什么大不了的)。

我尝试过分析并尝试使用属性,但似乎没有任何帮助。为了进行分析,我仍然必须为每个不同版本的 uild 手动更改父包版本。

有人可以帮忙吗。

谢谢

java eclipse maven apache-nifi
1个回答
0
投票

好吧,提前说一句,维护项目的多个版本可能不是一个好主意。 有没有尝试过统一依赖版本?

好吧,简而言之,我提供一个实现供参考; 您可以尝试使用maven配置文件来管理不同的版本并在不同的jdk中构建它们

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <groupId>nifi</groupId>
    <artifactId>ContollerService</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <modules>
        <module>ContollerService-api</module>
        <module>ContollerService-api-nar</module>
        <module>ContollerService</module>
        <module>ContollerService-nar</module>
    </modules>

    <profiles>
        <profile>
            <id>nifi-1.16.0</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <nifi.version>1.16.0</nifi.version>
                <java.version>1.8</java.version>
                <parent.artifactId>nifi-nar-bundles</parent.artifactId>
            </properties>
        </profile>
        <profile>
            <id>nifi-2.0.0-M3</id>
            <properties>
                <nifi.version>2.0.0-M3</nifi.version>
                <java.version>21</java.version>
                <parent.artifactId>nifi-extension-bundles</parent.artifactId>
            </properties>
        </profile>
    </profiles>

    <dependencyManagement>
        <dependencies>
            <!-- NiFi dependencies -->
            <dependency>
                <groupId>org.apache.nifi</groupId>
                <artifactId>nifi-api</artifactId>
                <version>${nifi.version}</version>
            </dependency>
            <!-- Add other dependencies as needed -->
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

© www.soinside.com 2019 - 2024. All rights reserved.