Specify version when deploying to nexus from maven

2019-07-20 01:43发布

问题:

I've forked Confluent's Kafka Connect HDFS writer and now I'd like to deploy a version of this jar to my local Nexus.

mvn clean deploy Works like a charm and deploys the jar.

https://[nexus]/repository/releases/io/confluent/kafka-connect-hdfs/5.0.0/kafka-connect-hdfs-5.0.0.jar

So far so good, but to make a distinction between the confluent versions and my own deployment I'd like to change the version of the build to something like 5.0.0-1 or so (preferably the tag name when pushed, but that's step 2)

The pom.xml is basically the same as the 5.0.0-post release, but here the most important parts:

    <parent>
        <groupId>io.confluent</groupId>
        <artifactId>kafka-connect-storage-common-parent</artifactId>
        <version>5.0.0</version>
    </parent>

    <artifactId>kafka-connect-hdfs</artifactId>
    <packaging>jar</packaging>
    <name>kafka-connect-hdfs</name>
    <organization>
        <name>Confluent, Inc.</name>
        <url>http://confluent.io</url>
    </organization>
    <url>http://confluent.io</url>
    <description>
        A Kafka Connect HDFS connector for copying data between Kafka and Hadoop HDFS.
    </description>
...
<dependencies>
    ...
    <dependency>
        <groupId>io.confluent</groupId>
        <artifactId>kafka-connect-storage-common</artifactId>
        <version>${confluent.version}</version>
    </dependency>
    <dependency>
        <groupId>io.confluent</groupId>
        <artifactId>kafka-connect-storage-core</artifactId>
        <version>${confluent.version}</version>
    </dependency>
    ...
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>io.confluent</groupId>
            <version>0.10.0</version>
            <artifactId>kafka-connect-maven-plugin</artifactId>
...

So first I added <version> tags to the pom.xml, but it started using that as the default for all confluent.version and complained that it couldn't find for example: https://[nexus]/repository/releases/io/confluent/kafka-connect-storage-hive/5.0.0-1/kafka-connect-storage-hive-5.0.0-1.pom

Next I tried the versions plugin from maven mvn versions:set -DnewVersion=5.0.0-1 clean deploy

But that complained about the parent:

[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.7:set (default-cli) on project kafka-connect-hdfs: Project version is inherited from parent. -> [Help 1]

I don't even care if the version is 5.0.0 in the code, I just wat to deploy to a different version in our artifactory.

I'm not a maven expert, so maybe I'm missing some very basic clue, but all help is welcome.

回答1:

So there were some good suggestions, but in the end the one thing that worked best for me in our setup was to use the deploy:deploy-file command for maven.

mvn deploy:deploy-file \
-Dfile=target/kafka-connect-hdfs-5.0.0.jar \
-DrepositoryId=[nexus id] \
-Durl=[nexus url] \
-Dversion=$TAG \
-DgroupId=io.confluent \
-DartifactId=kafka-connect-hdfs

The major downside was that I had to respecify parameters that were already present in the pom.xml (artifactId, groupId, ect), but it works, and that's what counts :-)



回答2:

You can specify the version with ${revision} parameter.

To do this, you need to add <version> tag with this variable in pom.xml:

<artifactId>kafka-connect-hdfs</artifactId>
<version>5.0.0-${revision}</version>
<packaging>jar</packaging>

And then provide it to the maven command. E.g., mvn clean package -Drevision=01 will generate kafka-connect-hdfs-5.0.0-01.jar file.