maven-deploy-plugin not executing its execution - maven

I need to deploy custom jar's from my project itself I overrides maven-deploy-plugin with two more execution with its default execution. below are my pom.xml with distributionManagement and maven-deploy-plugin which I use for my deployment.
<groupId>mycompany</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<distributionManagement>
<repository>
<id>temp</id>
<name>Release Repository</name>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
some dependency
</dependency>
<dependency>
some dependency
</dependency>
<dependency>
some dependency
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>myjar-one</id>
<phase>deploy</phase>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-one</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<sources>${project.build.directory}/build/lib/myjar-one.jar</sources>
</configuration>
</execution>
<execution>
<id>myjar-two</id>
<phase>deploy</phase>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-two</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<sources>${project.build.directory}/build/lib/myjar-two.jar</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Guys I figure out the issue, there are following thing I need to fix.
Need to add goal.
Need to use file tag instead of source tag.
So final maven-deploy-plugin looks like.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>myjar-one</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-one</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/build/lib/myjar-one.jar</file>
</configuration>
</execution>
<execution>
<id>myjar-two</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-two</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/build/lib/myjar-two.jar</file>
</configuration>
</execution>
</executions>
</plugin>
after fixing this issue, my both custom jar's are deployed at my maven repository. Thanks for help

Related

Maven release failing : A zip file cannot include itself

I am facing an issue while releasing a Maven project to nexus repository. I am doing this by Jenkins job. I am getting the error:
Failed to execute goal org.apache.maven.plugins:maven-source-plugin:3.0.1:jar (attach-sources) on project xyz: Error creating source archive: A zip file cannot include itself -> [Help 1]
I am using maven assembly plugin and external.atlassian.jgitflow:jgitflow-maven-plugin.
I have followed below article on StackOveflow : A zip file cannot include itself - Maven-assembly plugin
But this did not solve the problem. Below is how I am using the plugin
<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>
<groupId>com.x</groupId>
<artifactId>y</artifactId>
<packaging>jar</packaging>
<version>2.0.0</version>
<name>myArtifact</name>
<url>http://maven.apache.org</url>
<distributionManagement>
<repository>
<id>myRepoId</id>
<url>http://my/repo/location/releases/</url>
</repository>
<snapshotRepository>
<id>mySnapshotRepoId</id>
<url>http://my/repo/location/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>myRepoId</id>
<url>http://my/repo/location/releases/</url>
</repository>
<repository>
<id>mySnapshotRepoId</id>
<url>http://my/snapshot/repo/location/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!-- http://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<profiles>
<profile>
<id>local</id>
<properties>
<build.profile.id>local</build.profile.id>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>pre_prod</id>
<properties>
<build.profile.id>pre_prod</build.profile.id>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<build.profile.id>prod</build.profile.id>
</properties>
</profile>
</profiles>
<build>
<testResources>
<testResource>
<directory>${project.build.directory}</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>external.atlassian.jgitflow</groupId>
<artifactId>jgitflow-maven-plugin</artifactId>
<version>1.0-m5.1</version>
<configuration>
<enableSshAgent>true</enableSshAgent>
<allowUntracked>true</allowUntracked>
<allowSnapshots>true</allowSnapshots>
<autoVersionSubmodules>true</autoVersionSubmodules>
<pushFeatures>true</pushFeatures>
<pushReleases>true</pushReleases>
<pushHotfixes>true</pushHotfixes>
<noDeploy>false</noDeploy>
<scmCommentPrefix>TC-61</scmCommentPrefix>
<flowInitContext>
<developBranchName>development</developBranchName>
<versionTagPrefix>My-APP-</versionTagPrefix>
</flowInitContext>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<tag>Release-${project.artifactId}-${project.version}</tag>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifest>
<mainClass>com.mains.MainClass</mainClass>
</manifest>
</archive>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>src/main/resources/config/${build.profile.id}</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/velocities/html</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
<!-- START: Maven Jacoco Plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<!-- Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed. -->
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>jacoco-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<!-- Ensures that the code coverage report for unit tests is created
after unit tests have been run. -->
<execution>
<id>jacoco-report</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
Can someone point me where I am making the mistake.
Thanks.

Tycho copy-dependencies do not include plugin dependencies

For one plugin in my tycho reactor I would like to copy a "pure-maven" dependency and its transitive ones in a folder named "lib/".
Currently if I use the copy-dependencies goal from maven-dependency-plugin, my dependency is correctly copied but the "plugin-dependencies" resolved by tycho are also copied, and I don't want those.
Any suggestion to achieve this goal ? I'm currently using the following code snippet
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${maven.groupid}</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any suggestions are welcome.
Following this discussion on Eclipse forums it seems that we can tell maven to only include dependencies coming from the current pom.xml file using a combination of excludeScope and includeScope tags.
This updated XML snippet does the job as expected
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${maven.groupid}</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<!-- The lines below are aimed at telling maven NOT TO COPY tycho dependencies. Do not remove those! -->
<!-- See: https://dev.eclipse.org/mhonarc/lists/tycho-user/msg05080.html -->
<excludeScope>system</excludeScope>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

maven pom - define a profile to customize plugin configuration

I have the following plugin in pom:
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<configuration>
<version>${phantomjs.version}</version>
<checkSystemPath>false</checkSystemPath>
<skip>${skipTests}</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
I'd like to define a new profile to customize the plugin configuration:
<profile>
<id>enduserTest</id>
<properties>
<tomcat.version>8.0.39</tomcat.version>
<skipTests>true</skipTests>
</properties>
<build>
<defaultGoal>clean verify cargo:run</defaultGoal>
<plugins>
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<configuration>
<version>${phantomjs.version}</version>
<checkSystemPath>false</checkSystemPath>
</configuration>
<executions>
<execution>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
Where the only difference is that <skip>${skipTests}</skip>
line.
Now I'd like to run mvn -PenduserTest but the configuration doesn't get overriden.
Any advice? is there a better solution to do this? is it the correct strategy?
If the desired behavior is that tests get skipped when running the profile, so your logic is not wrong. to verify i test this code and this is work as expected (it skip tests with -PenduserTest) :
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<version>0.7</version>
<configuration>
<version>2.1.1</version>
<checkSystemPath>false</checkSystemPath>
<skip>${skipTests}</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source />
<target />
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>enduserTest</id>
<properties>
<tomcat.version>8.0.39</tomcat.version>
<skipTests>true</skipTests>
</properties>
<build>
<defaultGoal>clean verify cargo:run</defaultGoal>
<plugins>
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<version>0.7</version>
<configuration>
<version>0.7</version>
<checkSystemPath>false</checkSystemPath>
</configuration>
<executions>
<execution>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Trying to copy denedecy bot not working

<modelVersion>4.0.0</modelVersion>
<artifactId>eau-claims-jar</artifactId>
<groupId>com</groupId>
<name>eau-claims-jar</name>
<packaging>jar</packaging>
<version>2.1.10.0-TIM3-SNAPSHOT</version>
<profiles>
<profile>
<id>build-4-eau</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- <version>2.10</version> -->
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com</groupId>
<artifactId>kcaps</artifactId>
<version>2.3.0.0-TIM2-SNAPSHOT</version>
<!-- <type>jar</type> -->
</artifactItem>
</artifactItems>
<outputDirectory>.</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Dependent kcaps jar is not getting downloaded. I am trying to build a jenkins job that downloads the dependent jar and copy to the server. Only eau-claims-jar jar is getting generated and copied but the dependent jar is not. any idea what i am doing wrong or any different approach?
http://www.egtry.com/tools/maven/dependency_copy
Tried how its in above link and it worked. still don't understand what was the issue with my pom.xml

How to dowload and rename dependency jars in pom.xml

Here is my pom.xml which is downloading the dependency jars- jsaf-3.5.jar and mal-1.5.0.jar But I want to remove the version part from the name.That is jsaf.jar and mal.jar Please suggest how to rename those jars in the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeTransitive>true</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.qsa.jsaf</groupId>
<artifactId>jsaf</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>javax.mal</groupId>
<artifactId>mal</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies>
</project>
Strip version from dependencies with parameter
<stripVersion>true</stripVersion>
Strip artifact version during copy
Sample configuration
<configuration>
<stripVersion>true</stripVersion>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeTransitive>true</excludeTransitive>
</configuration>

Resources