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

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>

Related

replace nexus staging maven plugin with maven-deploy-plugin

Our project inherits nexus staging maven plugin from a parent pom which we don't have control on. I have this configuration in my root pom to disable the nexus staging maven plugin and this configuration seems to disabling the default-deploy execution.
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<serverId>nexus</serverId>
<nexusUrl>url</nexusUrl>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
</plugin>
and I have the maven deploy plugin defined in my root pom, but the maven-deploy plugin seems to be not kicking off
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
I am not able to figure out how i can replace the inherited nexus staging maven plugin with the maven deploy plugin. Any help is much appreciated
You may qualify the goal by the plugin groupID:artefactID:
mvn org.apache.maven.plugins:maven-deploy-plugin:deploy
I faced a similar issue, and for success disabling of nexus-staging-maven-plugin I only need to add following to my main pom:
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<extensions>false</extensions>
</plugin>
And as one of my dependencies was disabling maven-deploy-plugin(I reccomend to check it also in your project) I also need to add:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>

Regarding updating pom file

I am working on a continuous integration tool and here i need to integrate jacoco plugin after checking out. I do not want to enforce developer to add jacoco plugin while checkin instead i would like to add it while running the jenkins based continuous integration tool.
Is it possible to achieve any of these options?:
1. to modify the pom file checked in by the developer and inject the dependency and plugin required for jacoco?
OR
to add the jacoco plugin super pom and mention that in jenkins configuration.
I tried this super pom approach, and it was reading super pom from a common repository, but not generating jacoco-exec file. I used below in super pom.
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
pom
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<destFile>${basedir}/target/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help will be appreciated. Thanks
You can create a separate profile in the pom.xml, name it as jenkins profile and include jacoco plugin in that profile. You can then configure the mvn command in your jenkins job to include -P jenkins_profile_name. So the build would be done using the jenkins profile configuration.
Mark the existing profile as default and developers won't need to do anything specific.
For more details, refer to maven documentation for build profiles:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html

How to create a private JAR in a local subdirectory which I have designated as an additional repository?

In a subdirectory under a project, I have a library module of code I write and maintain that must be shared with other modules in the larger project. For convenience, it's developed simultaneously alongside all the modules consuming it.
project
libs
module-A
module-B
module-N
library-module
For complicated reasons imposed by how our build is done after it leaves our hands, we don't want it deployed to the build host's local Maven repository (~/.m2/repository). Instead, we want it in a subdirectory local to the project, here libs.
From the command line, I know the following will put it into the local Maven repository, but I don't want to do this from the command line and I don't want the result to go to the local Maven repository. I want this to happen when mvn install is run by the build system in the library-module subdirectory.
mvn install:install-file -Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-Dsources=src.jar] \
[-Djavadoc=apidocs.jar] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=sources] \
[-DgeneratePom=true] \
[-DcreateChecksum=true]
(Note that the answer I'm looking for would not be IDE-dependent.)
To meet the provided requirements, two configuration steps are then required:
Disable the default artifact installation to the local repository, via the skip option of the Maven Install Plugin
Configure the install-file goal within the POM in order to have it as part of your build (hence no need to invoke it manually from command line)
The following configuration would provide it:
<properties>
<library.repository.folder>../libs</library.repository.folder>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>install-artifact</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>${project.packaging}</packaging>
<file>${project.build.directory}/${project.build.finalName}.${project.packaging}</file>
<localRepositoryPath>${library.repository.folder}</localRepositoryPath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Please note the library.repository.folder property used to point to the desired target lib folder (to change in case of different path). The configuration provided above makes use of standard maven properties (for project coordinates and packaging), but you can change them (or hard-code real values) as required.
Also note that the install-file goal will recreate under the lib folder the same folders structure as in the local repository (lib\groupId\artifactId\version\file.jar). If you instead would like to have the file straight under the lib folder (lib\file.jar) you could then move to the following configuration:
<properties>
<library.repository.folder>../libs</library.repository.folder>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${library.repository.folder}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
This time we are not using the install-file goal but rather the jar goal of the Maven Jar Plugin to place the packaged artifact directly to the lib folder (instead of the standard target folder) and during the package phase (not install).
If by any reason you want to keep the final artifact in the target folder AND have it straight copied to the lib folder (no maven folders hierarchy) AND during the install phase, then you could move to the following configuration:
<properties>
<library.repository.folder>../libs</library.repository.folder>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>re-package-into-lib</id>
<phase>install</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${library.repository.folder}</outputDirectory>
</configuration>
</execution>
</executions>
</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>

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

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>

Resources