Maven deploy plugin override error? - maven

I am trying to override deploy plugin for maven and get the following error on some of my projects but not others:
Execution default-deploy of goal org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy failed: Cannot add two different pieces of metadata for:
Here is my plugin definition:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<pomFile>target/modified-pom-replacePomPlaceholder/modified-pom/pom.xml</pomFile>
</configuration>
</execution>
</executions>
</plugin>
Also tried this to same effect:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<pomFile>target/modified-pom-replacePomPlaceholder/modified-pom/pom.xml</pomFile>
</configuration>
</plugin>
Any idea why it fails sometimes?

Don't override 'default-deploy'. Deactivate it and write your own:
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>my-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
...
</execution>

Maybe a little bit late, but here my assumption:
run maven with debug output on, e.g. mvn clean deploy -X, then check the debug output, especially the following two lines:
[DEBUG] (f) pomFile = /home/rotscher/projects/localswap/localswap-web/target/pom.xml
[DEBUG] (f) project = MavenProject: ch.rotscher.localswap:localswap-web:1 # /home/rotscher/projects/localswap/localswap-web/target/pom.xml
The paths should be equals (according to java.io.File.equals).
So, I guess your solution could be to configure the path of pomFile with ${basedir}:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<pomFile>${basedir}/target/modified-pom-replacePomPlaceholder/modified-pom/pom.xml</pomFile>
</configuration>
</plugin>

Related

using maven dependency (:copy) plug in not working

I can't seem to figure this out.
I have the following in my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
I plan to have all the dependencies copied to target/lib directory.
Why is not doing it?
My project is evolving, so I do not want specify each individual artifact to copy. I want it to take them all, and place it into a proper place during the "package" (or compile) phase.
I get only my mainProject.jar file in the lib folder.
Please, help. What am I missing?
The correct goal for copying dependencies is copy-dependencies, not compile. Also, if you want to invoke the plugin from the command line with mvn dependency:copy, the configuration section should not be inside the executions. Here is a configuration that should work in all cases:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</plugin>
As you can see, I'm running the plugin in the 'package' phase, but it also works in the 'compile' phase, unless you want to include the artifact just built by your own project.

Maven Config Plugins running twice

I have the following pom config. I added the cobertura plugin, and now pmd, cpd, findbugs, and test are running twice.
I understand that is because of my "phases" config, but I don't understand how can I achieve the following:
What I want is before I commit to the repo, build my app and check for pmd errors, findbugs errors, check my tests, and check my cobertura.
How can I achieve this? I am used to run "mvn clean package" before commit. It's that ok?
Here's my config:
...
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<linkXref>false</linkXref>
<rulesets>
<!-- Custom Ruleset -->
<ruleset>codequality/pmd.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>70</branchRate>
<lineRate>70</lineRate>
<totalBranchRate>70</totalBranchRate>
<totalLineRate>70</totalLineRate>
<packageLineRate>70</packageLineRate>
<packageBranchRate>70</packageBranchRate>
</check>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any maven plugin has a default execution phase. In this case, the plugins that you apply are executed in the verify phase (pmd-plugin). But you are defining it to run also in the compile phase. Removes the phase tag and lets it run in the verification phase.
<execution>
<!--<phase>compile</phase>-->
<goals>
<goal>...</goal>
...
</goals>
</execution>
Finally, the good practice to validate your project before a commit is to run:
mvn clean verify

Override filename in maven when deploying file

I generate zip file in maven-assembly-plugin with specific name and want be able to deploy it.
I define $[my-version} property in initialize phase and I successfully get the file, but when deoplying I get the following error:
[ERROR]
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli)
on project my-project: C:\Users\pr\work\my-project\target\target\my-file-${my-version}.zip not found.
-> [Help 1]
Code:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<file>target/my-file-${my-version}.zip</file>
<repositoryId>releases</repositoryId>
<url>${nexus.url}/content/repositories/releases</url>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<finalName>my-file-${my-version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/deployment.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
The problem was in order of phases. When calling goal "deploy:deploy-file" directly, the phase "intialization" wasn't processed.
So, one of the ways is to call it explicitly:
mvn initialize deploy-file

How to resolve a Maven "The packaging for this project did not assign a file to the build artifact" error?

I’m using Maven 3.2.3. I used to be able to run “mvn clean install” on my WAR project and the WAR would get installed to my local repository. However, I recently added a configuration so that my WAR would be constructed in place (config is below). Now, when I run
mvn clean install
I get the error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.5.2:install (install) on project myproject: The packaging for this project did not assign a file to the build artifact -> [Help 1]
How do I fix this? I tried making the “install” goal of the maven-install-plugin the default, but that didn’t help. Below is my Maven configuration …
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/classes</directory>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
<workDirectory>/tmp/${project.artifactId}/war/work</workDirectory>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>none</phase>
</execution>
<execution>
<id>war-inplace</id>
<phase>package</phase>
<goals>
<goal>inplace</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
Adding the below rpm entry
%_rpmfilename noarch/%%{NAME}-%%{VERSION}-%%{RELEASE}.noarch.rpm
in each of the following files mentioned here solved the problem for me. (from 64 to no-arch).
vim /etc/rpm/macros
vim ~/.rpmmacros

Adding JVM args AND jacoco-maven-plugin?

Just wanted to know if it's usefull to start the jacoco agent using the maven plugin and to add some arguments to surefire ? Does it start Jacoco twice ?
Example :
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
And
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:${sonar.jacoco.jar}=destfile='${sonar.jacoco.reportPath}'</argLine>
They provide Maven usage example, so it seems additional arguments for Surefire are not needed.
I don't know what your ${jacoco.version} is, but the following snippet worked for me.
You don't need to provide additional arguments for the surefire plugin.
The version has to be one that is declared in the Maven Repository( Assuming that you didn't install the dependency locally or use some other/custom repository):
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.7.201204190339</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>

Resources