Jenkins "Post Build Action" to deploy zip on Maven repository - maven

I Have recently started using Jenkins and currently using version 1.492. I have a Maven module project which produces a Jar and a Zip files which I want to deploy to a Nexus Maven repository.
When I build my project locally I get the message :
Installing PROJECT_DIR/target/groupID/projectId-version.jar to LOCAL_REPO/ groupID/projectId-version.jar
Installing PROJECT_DIR /groupID/projectId.zip to LOCAL_REPO/ groupID/projectId/version/ projectId-version-classifier.zip
Using the "Post Build Action" Deploy artifacts to Maven repository. On the Jenkins build logs I can see my jar is deployed but nothing about my zip.
Is there a specific config to fix it?

Configure your project to attach additional zip artifact.
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>some file</file>
<type>extension of your file </type>
<classifier>optional</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Related

maven: With one pom.xml I am creating jar and tar.gz but don't want to deploy jar

With one pom.xml first I am creating a jar file with maven-jar-plugin and signing it with maven-jarsigner-plugin, second I am creating a tar.gz package with maven-assembly-plugin, copying jar file and other necessary files into tar.gz. Just because only tar.gz package is enough for me, I want only tar.gz package to deploy remote repository. When I run the "mvn deploy" command, both the jar and tar.gz packages are being deployed. Are there any method for not to deploy jar file to remote repository.
I tried your suggestion. It is not working for maven-deploy-plugin but it is working for maven-install plugin. Here is the relative part of my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}-dev.tar.gz</file>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<packaging>tar.gz</packaging>
<version>${project.version}</version>
<classifier>dev</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<url>http://repo/artifactory/snapshots</url>
<file>${project.build.directory}/${project.build.finalName}-dev.tar.gz</file>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<packaging>tar.gz</packaging>
<version>${project.version}</version>
<classifier>dev</classifier>
</configuration>
</execution>
</executions>
</plugin>
maven-install-plugin is installing only tar.gz file to local repository but maven-deploy-plugin deploying both tar.gz and jar files to remote repository. I think this behaviour can be maven-deploy-plugin's bug.
By default the Maven Deploy plugin will deploy all the artifacts attached to your project or module, i.e. both your .jar and tar.gz file.
deploy:deploy is used to automatically install the artifact, its pom and the attached artifacts produced by a particular project.
What you can do is skip the deploy:deploy goal and configure a personalized deploy:deploy-file goal, such as:
<build>
...
<plugins>
...
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip> <!-- Skip the default deploy -->
</configuration>
<executions>
<!-- Deploy our tar.gz -->
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}.tar.gz</file>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<packaging>tar.gz</packaging>
<version>${project.version}</version>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
You'll have to configure <file> to use your generated tar.gz file.

is it possible to version and deploy a configuration file to nexus via maven commands

I am working on a java project and I would like to version and store a configuration file on nexus. Lets assume the file structure of java project is as below.
src/
conf/application.config
pom.xml
Is it possible to deploy application.config file to nexus when I run mvn clean install. After each build I expect an application artifact and a configuration artifact to be deployed to nexus. Is there any maven plugin for this purpose.
I manged to deploy file with maven-deploy-plugin.
http://maven.apache.org/plugins/maven-deploy-plugin/usage.html
You can find an example below.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-file</id>
<!-- change to deploy-->
<phase>install</phase>
<goals>
<goal>deploy-file</goal>
</goals>
</execution>
</executions>
<configuration>
<file>app.properties</file>
<repositoryId>stack.example.release</repositoryId>
<url>http://nexusserver/nexus/content/repositories/releases/</url>
<groupId>com.stack.example.config</groupId>
<artifactId>app</artifactId>
<packaging>properties</packaging>
<version>1.0.0</version>
</configuration>
</plugin>
</plugins>
</build>

How to publish hadoop-dist-*.tar.gz with maven

We use maven to publish hadoop artifacts to an Artifactory installation. By default, the jars are published, but we'd also like the hadoop-dist tarball published.
To publish the JARs, we run something like this:
mvn -e 'clean package deploy' -Pdist -DskipTests -Dtar -Dmaven.javadoc.skip
This does build the hadoop-dist tarball, but doesn't publish it.
What extra args do we need to get the dist tarball published too?
Updated: Dist profile included below, as per request in the comments.
<profile>
<id>dist</id>
<!-- Profile for generating all maven artifacts and documentation. -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<!-- build aggregate javadoc in parent only -->
<id>default-cli</id>
<goals>
<goal>aggregate</goal>
</goals>
<configuration>
<overview>hadoop-common-project/hadoop-common/src/main/java/overview.html</overview>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Deploy xml files during maven release

During maven release process, maven will try to help you upload source, javadoc, and jar into nexus or artifactory, except those, I also want to upload something such as xml files.
Any one know how to config it? Maven deploy plugin seems very simple and dont provide such configuration for users.
Should I have to use deploy file goal instead? Or other ways?
Any comments are welcome.
Br,
Tim
Simplest solution for such things is to use the build-helper-maven-plugin like this:
<project>
...
<build>
<plugins>
<plugin>
<!-- add configuration for antrun or another plugin here -->
</plugin>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>some file</file>
<type>extension of your file </type>
<classifier>optional</classifier>
</artifact>
...
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
You can also create a separate resources package and use it via maven-remote-resources-plugin in other projects.

is is possible to install the source and javadoc jar to maven repository along with a single command `mvn clean all`

As we all know that using mvn clean install will install the built package,eg jar, zip, pom, to local repo , but source and javadoc jar . Can I make some changes on pom.xml so that source and jardoc jar would be installed to local repo with mvn clean install
Yes, what you want to do is to add the maven-source-plugin and maven-javadoc-plugin to your pom. This will cause the jar goal to execute automatically during the package phase without needing to specify it on the command line.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
...
<plugins>

Resources