'Jenkins Artifactory Plugin - Maven wrapper not publishing custom artifacts which have been installed

When building my Maven project, I expect the Jenkins Artifactory Plugin to deploy/publish artifacts which I successfully maven-install (ie, copied from the /target folder to my local maven repo).

The Jenkins-Artifactory plugin binds to the install phase of the Maven lifecycle. It is publishing the pom files for the modules of my project, but not the build files I need (which I have installed).

UPDATE: JFrog have confirmed this is a bug with the plugin: https://github.com/jfrog/jenkins-artifactory-plugin/issues/665 - I will post an update to this question once it is resolved.

PLEASE NOTE: A normal pom which simply creates a jar works as expected. This is specifically to do with publishing a custom artifact type having used the maven-install-plugin.

Some details:

  • The build process creates .bar files
  • These .bar files are added to /target using the maven-install-plugin execution shown below
  • The .pom files are being uploaded to Artifactory
  • The .bar files are not being uploaded to Artifactory
<execution>
  <id>custom-install</id>
  <phase>install</phase>
  <goals>
      <goal>install-file</goal>
  </goals>
  <configuration>
      <generatePom>true</generatePom>
      <groupId>${project.groupId}</groupId>
      <artifactId>${project.artifactId}</artifactId>
      <version>${project.version}</version>
      <file>${project.build.directory}/${project.build.finalName}.bar</file>
      <packaging>bar</packaging>
  </configuration>
</execution>

Logs:

16:50:39  [main] INFO org.apache.maven.cli.event.ExecutionEventLogger - --- maven-install-plugin:2.5.2:install-file (custom-install) @ MyMavenModule ---
16:50:39  [main] INFO org.codehaus.plexus.PlexusContainer - Installing /opt/jenkins/workspace/my-project/build/develop/2/MyMavenModule/target/MyMavenModule-1.0.0.bar to /home/jenkins-user/.m2/repository/my/project/group/MyMavenModule/1.0.0/MyMavenModule-1.0.0.bar
16:50:40  [pool-1-thread-1] INFO org.jfrog.build.extractor.maven.ArtifactoryManagerBuilder - [pool-1-thread-1] Deploying artifact: https://artifactory.mycompany.com/artifactory/libs-local/my/project/group/MyMavenModule/1.0.0/MyMavenModule-1.0.0.pom

Versions:

  • Jenkins: 2.332.1
  • Artifactory: 6.16.0 Pro
  • Jenkins Artifactory Plugin: 3.16.1
  • Maven: 3.8.5
  • Maven install plugin: 3.0.0-M1

Pipeline / Plugin configuration

rtMavenResolver (
        id: "resolver-${config.serverKey}",
        serverId: config.serverKey,
        releaseRepo: config.repos.resolve.release,
        snapshotRepo: config.repos.resolve.snapshot
)

rtMavenDeployer (
        id: "deployer-${config.serverKey}",
        serverId: config.serverKey,
        releaseRepo: config.repos.deploy.release,
        snapshotRepo: config.repos.deploy.snapshot,
        deployArtifacts : config.deployArtifacts,
        includePatterns: config.repos.deploy.includePatterns,
        excludePatterns: config.repos.deploy.excludePatterns,
        properties: config.repos.deploy.properties,
)

rtBuildInfo (
        captureEnv: true,
        buildName: config.buildName,
        buildNumber: config.buildNumber
)

def mvn(goals) {
    rtMavenRun (
            tool: config.tools.maven,
            pom: 'pom.xml',
            goals: "-U -e -B -V -Dstyle.color=always $goals",
            opts: '-Dmaven.test.failure.ignore=false -Djansi.force=true',
            deployerId: "deployer-${config.artifacts.serverKey}",
            resolverId: "resolver-${config.artifacts.serverKey}",
            buildName: config.artifacts.buildName,
            buildNumber: config.artifacts.buildNumber
    )
}

<<<snip>>>

mvn 'install -Dmaven.test.skip=true -DskipTests'

Reproducible Example:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd"
        >
    <modelVersion>4.0.0</modelVersion>
    <url>http://maven.apache.org</url>

    <groupId>com.example</groupId>
    <artifactId>MyModule</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <exec-maven-plugin-version>1.6.0</exec-maven-plugin-version>
        <maven-install-plugin-version>3.0.0-M1</maven-install-plugin-version>
    </properties>

    <build>
        <plugins>
        
        <!-- Note: See 'http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html' for details -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>${maven-install-plugin-version}</version>
                <executions>
                    <execution>
                        <id>default-install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>install</goal>
                        </goals>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>custom-install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <generatePom>true</generatePom>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <file>${project.build.directory}/${project.build.finalName}.bar</file>
                            <packaging>bar</packaging>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>


    <profiles>
        <profile>
            <id>Windows</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>${exec-maven-plugin-version}</version>
                        <executions>
                            <execution>
                                <id>execution.compile.windows.buildBAR</id>
                                <phase>compile</phase>
                                <configuration>
                                    <workingDirectory>${project.build.directory}</workingDirectory>
                                    <executable>buildBAR.cmd</executable>
                                    <arguments>
                                        <argument>${iib.toolkit.path.windows}</argument>
                                        <argument>${project.artifactId}</argument>
                                        <argument>${project.build.finalName}</argument>
                                    </arguments>
                                </configuration>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <version>${exec-maven-plugin-version}</version>
                            <executions>
                                <execution>
                                    <id>execution.compile.unix.buildBAR</id>
                                    <phase>compile</phase>
                                    <configuration>
                                        <workingDirectory>${project.build.directory}</workingDirectory>
                                        <executable>sh</executable>
                                        <arguments>
                                            <argument>buildBAR.sh</argument>
                                            <argument>${project.artifactId}</argument>
                                            <argument>${project.build.finalName}</argument>
                                        </arguments>
                                    </configuration>
                                    <goals>
                                        <goal>exec</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
</project>

buildBAR.cmd

SET moduleName=%1
SET barfileName=%2
echo %moduleName% > %barfileName%.bar

buildBAR.sh

#!/bin/sh
moduleName=$1
barfileName=$2
echo $moduleName > $barfileName.bar

mvn clean install yeilds:

PS C:\dev\barbuilder> mvn clean install
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< com.example:MyModule >------------------------
[INFO] Building MyModule 1.0.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MyModule ---
[INFO] Deleting C:\dev\barbuilder\target
[INFO]
[INFO] --- exec-maven-plugin:1.6.0:exec (execution.compile.windows.buildBAR) @ MyModule ---

C:\dev\barbuilder\target>SET moduleName=MyModule 

C:\dev\barbuilder\target>SET barfileName=MyModule-1.0.0-SNAPSHOT      

C:\dev\barbuilder\target>echo MyModule  1>MyModule-1.0.0-SNAPSHOT.bar 
[INFO] 
[INFO] --- maven-install-plugin:3.0.0-M1:install (default-install) @ MyModule ---
[INFO] Skipping artifact installation
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install-file (custom-install) @ MyModule ---
[INFO] Installing C:\dev\barbuilder\target\MyModule-1.0.0-SNAPSHOT.bar to C:\Users\denham.coote\AppData\Local\.m2\repository\com\example\MyModule\1.0.0-SNAPSHOT\MyModule-1.0.0-SNAPSHOT.bar
[INFO] Installing C:\Users\DENHAM~1.COO\AppData\Local\Temp\mvninstall1034342466988970935.pom to C:\Users\denham.coote\AppData\Local\.m2\repository\com\example\MyModule\1.0.0-SNAPSHOT\MyModule-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.217 s
[INFO] Finished at: 2022-04-04T12:29:59+01:00
[INFO] ------------------------------------------------------------------------
PS C:\dev\barbuilder> 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source