I am using mvn release-plugin and assembly-plugin to deploy jar with dependency. It works fine, when I use it with mvn release. It creates two files: normal XXX.jar and XXX.jar-with-dependencies.jar and deploys them both.
But I need also deploy snapshot to another repository by using mvn deploy. In this repository I only need the XXX.jar without dependencies.
So I hope that I could use mvn deploy to deploy snapshot version without dependencies with followed setting.
POM.xml setting:
...
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>install</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
...
PS: mvn clean install deploy will be called by jenkins scm pulling schedule every morning.
Artifacts produced by maven-assmbly-plugin are automatically attached to the project and hence are deployed when you call mvn deploy.
What you can do is to define a profile (say 'with-dependencies') where you put the assembly plugin execution. In this case if you call mvn deploy it will build a -SNAPSHOT version and push it to the snapshot repository and for the release you will have to call mvn release:prepare release:perform -Pwith-dependencies
<profile>
<id>with-dependencies</id>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>install</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</profile>
Related
My project generates two jar: the original-artifact-name.jar and the artifact-name.jar (I have shade plugin setup).
I want to use mvn release:prepare and mvn release:perform and be able to deploy not only the simple jar but also the origial one.
So far I am invoking the mave deploy:file goal manually after the release plugin has been executed. How can I incorporate this step in the release plugin execution?
Edit: this is my attempt with maven-deploy-plugin:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-nodeps</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/original-${project.artifactId}-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<classifier>nodeps</classifier>
<url>${project.distributionManagement.repository.url}</url>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>
which for some reasons is deploying the main jar in the snapshot repo, while the nodeps jar in the release repo. This is my repositories setup
<repositories>
<repository>
<id>maven-snapshots</id>
<url>https://repo.com/maven-snapshots</url>
</repository>
<repository>
<id>maven-releases</id>
<url>https://repo.com/maven-releases</url>
</repository>
If you want to deploy additional files, you can configure the deploy:deploy-file goal in the POM.
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>deploy-bo</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/bo.jar</file>
<pomFile>${basedir}/target/somewhere/pom-bo.xml</pomFile>
<url>${project.distributionManagementArtifactRepository.url}</url>
<repositoryId>${project.distributionManagementArtifactRepository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>
I have few dependencies in my pom.xml file and used below assembly-plugin to create a jar with all dependencies.
Create created a final jar as {{artifact-id}}-{{version}}-jar-with-dependencies.jar
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
From Teamcity, i have added Maven build step and enabled artifactory settings as below,
Artifactory server URL: https://artifactory.***/artifactory
Target repository: libs-release-local
Target snapshot repository: libs-snapshot-local
And added following maven lifecycle - clean test package. here on Success, it publish the jar to respective folder in artifactory with {{artifact-id}}-{{version}}-jar-with-dependencies.jar
Case:
Need to deploy the jar without "-jar-with-dependencies" to artifactory
Changes in Pom:
Did following changes,
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId> <finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
Issue:
With above changes, it is working fine with maven package command in local environment.
But while executing from teamcity it is NOT publishing the Jar to the Artifactory..
could you please redirect to resolve the issue?
I have a requirement, where i need to execute a plugin before running unit tests or system tests. Is there any way i can make sure that my plugin executes before mvn test
Sure. Maven build lifecycle runs in phases. Your plugin can be configure to run in a specific phase.
So you can configure it to run in compile phase or in test phase (just declare it before the maven-surefire-plugin for test phase)
Example of configuring plugin phase:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
I am trying to build multiple Maven profiles in a single Jenkins job. Each profile changes some code and then creates a jar by executing mvn -Pdev install then mvn -Pprod install in the command line (According to Maven using mvn -Pdev,prod install is supposed to work but it isn't working for me). Here are the two profiles in my project's pom.xml:
<profiles>
<!-- prod profile -->
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>src/main/java/com/IQzone/android/configuration/AbstractHoldingRefreshable.java</file>
<replacements>
<replacement>
<token>TrUe</token>
<value>TOAST_SWITCH</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>prod</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- dev profile -->
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>src/main/java/com/IQzone/android/configuration/AbstractHoldingRefreshable.java</file>
<replacements>
<replacement>
<token>TOAST_SWITCH</token>
<value>TrUe</value>
</replacement>
</replacements>
</configuration>
</plugin>
<!-- build project with JAVA 1.6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>dev</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
How would I setup Jenkins to automatically build both of these profiles for a single Jenkins job whenever the job is hit for a build? And put both of these jars in the Artifactory? I have very little Jenkins knowledge and there isn't much information on this on the web.
You could create a Jenkins matrix job. A matrix job allows the same job to run with changing settings (in your case: a string).
Each changing setting is called an axis. In your case you would create a string axis containing the two values: dev and prod.
That way your job would run twice, with both values.
However: your usage of profiles is dangerous. Since the profile used to run the build is not codified into your artifact, your break the "one source revision should always lead to exactly the same target artifact" contract of Maven (see: http://www.blackbuild.com/how-to-really-use-maven-profiles-without-endangering-your-karma/ for a more detailed explanation)
Consider creating either two different artifacts using classifier (-dev and -prod) or even better: create two separate modules of your build, each one creating only one of your target artifacts.
In Maven, if you use mvn -Pdev,prod, then you are activating both profiles simultaneously in one command.
It seems you want 2 distinct run of the command, i.e. something you would achieve on the command line by doing 2 builds:
mvn -Pdev install; mvn -Pprod install
In jenkins you can achieve this with either
one free style project job (with 2 shell builders running the mvn -P$PROFILE install tasks)
2 maven type jobs (that you can chain one after the other using "build after other projects are built").
In addition to Matrix job and multiple maven invocations in a free-style job, there's another way: Run top-level Maven targets as a pre-build step and run the other command via maven jenkins plugin.
Make sure that the pre-build step uses the same maven repo as the other command by supplying -Dmaven.repo.local=/${whatever-it-is}/${EXECUTOR_NUMBER}.
Please refer to other answers for details on matrix job, etc.
You can do it by setting different execution ids to each execution and then trigger the command
mvn -Pdev,prod clean package install
I am using maven assembly plugin. in my pom.xml, pakaging type: jar and i dont use maven jar plugin.
Whenever i run mvn clean package, it create 2 jar files: one is from maven assembly, another one is created by default (due to packaging type =jar). I want to keep only the jar file created by assembly plugin only. How to do that?
You may have your reasons but I doubt that it is a good solution to skip the default jar being built and deployed.
Anyhow here is how you can disable the default jar being built.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- some configuration of yours... -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<!-- put the default-jar in the none phase to skip it from being created -->
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>