Eclipse maven-jar-plugin not signing, because of duplicate entries pom.xml and pom.properties only on Windows - windows

I searched a lot, but I have not found any solution for this.
Environment
*** Eclipse Java EE IDE for Web Developers. Version: Kepler Release - Build id: 20130614-0229 with m2e-wtp - Maven Integration for WTP
1.0.0.20130612-1742
*** Windows 7 up to date
*** Java SDK 1.7.0-40
*** Maven: Embedded (3.0.4/1.4.0.20130531-2315)
Problem
Errors:
Signing jars with (apache)maven-jar-plugin:2.4:sign (signing) on Linux works fine! The same maven project on Windows leads to the following error:
[INFO] jar is unsigned. (signatures missing or not parsable)
[ERROR] jarsigner: unable to sign jar: java.util.zip.ZipException: duplicate entry: META-INF/maven/.../pom.xml
Other messages:
I spotted different outputs between Linux and Windows from (apache)maven-jar-plugin:2.4:jar (default-jar)
Linux-Eclipse skips both files, because were already added:
...
[INFO] META-INF/maven/com.xyz/abc-client/pom.xml already added, skipping
[INFO] META-INF/maven/com.xyz/abc-client/pom.properties already added, skipping
...
after that the signing works fine!
The Windows ouput is not showing these two lines!!
Additional Information:
I can not use the (apache)maven-jarsigner-plugin, because it will lead to following error - without solution:
[ERROR] jarsigner: cannot rename file jarfile.jar to .orig`
This github-forum website tells me that the m2e-wtp-plugin of
Eclipse causing the problem, and that I should use maven on command
line .... this is the absolutely last option to use!!!
There is also a bug "MPIR-286" on codehouse for this, but still unresolved.
The clean part is done by the plugin and it's the same configuration for a client-module build before the one causing the problem.
Question:
Is there a possibility to get rid of this error? I cannot use the jarsigner-plugin, because of the "rename"-error and not the jar-plugin, because of the "duplicate entry"-error ... that is in fact a very strange situation.

This is the solution by the question's author, moved to the appropriate section.
To question's author: if you want to gain reputation, feel free to write a new answer, then ping me to remove this answer.
So I found it out myself. Here is what helped me to fix the problem.
Research
I found this question after more research and they stated, that the maven.archiver is the cause, because it wants to create the both files after they have been copied into the jar from m2e.mavenarchiver-plugin.
"... the m2e.mavenarchiver is creating pom.xml files etc. in the target directory, then these get pulled in by the maven archiver maven plugin, which then also creates its own files - hence the duplicates."
So the solution is also stated on this topic site.
Solution
Add
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
to your pom.xml

In my case
maven clean install fixed this issues
Make use of this Java Decompiler
for Viewing the jar whether it has a Duplicate pom.xml and properties

I have added below plugin that worked :
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>

Related

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin: 3.0.0-M4 (default-test). There are test failures- JENKINS

I did download the project from github without any problem, i provided th maven commands mvn clean install and the project build successfully but when it comes to run the tests i get the following error. Any hints? I'am providing my pom.xml file, i tried all the suggestions but nothing.
Does your pom.xml contains the plugin surefire tag ? If thats missing then maven wont download this plugin at runtime and hence the error. Also if its there but maven cant download then may be you have to allow internet connectivity or copy the jars manually inside the .m2 directory on the Jenkins/Node server machine.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>

Maven Compile Access Denied Copying Dependencies

I have a weird problem with Maven that I've not run into before. I appear to be the only one having the problem on my team and this is for a project that has existed for a significant period of time (10+ years). I'm new to the team, but so are other members who do not seem to be having this problem.
Here's the problem:
If I do a mvn clean compile, I get the following error:
[ERROR] Failed to execute goal org.codehaus.mojo:dependency-maven-plugin:1.0:copy (copy-dependencies)
on project deployable-war: Error copying artifact
from C:\...\dependency\target\classes
to C:\...\deployable-war\target\dependency\jws\lib\classes:
C:\...\dependency\target\classes (Access is denied) -> [Help 1]
Now, the weird part is that source and destination folders (dependency\target\classes and deployable-war\target\dependency\jws\lib\classes) were both created by Maven during the same compile command. This is a multi-module project, so mvn compile will go through all 9 modules. This is module 8. The dependency module is module 7.
If I re-run mvn compile (without the clean) afterwards, it gives the same error, so it does not seem to be a timing issue.
If I manually create the folder (mkdir ...\deployable-war\target\dependency\jws\lib\classes) and re-run mvn compile, everything works fine. That includes it copying JAR files inside of the lib folder that it said was access denied when it tried to create the classes folder.
I've tried deleting the \target\ folder entirely.
I've tried running Maven as an administrator.
I've tried checking out a new copy of the project from Git into a new directory on my local.
I've checked folder permissions on the project itself to ensure that my user and the administrator user have full control.
OS is Windows 10 Enterprise.
Any suggestions?
EDIT: From discussion, tracked the error down to this part of the pom.xml for the module:
<build>
<finalName>deployable</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dependency-maven-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.build.finalName}/jws/lib</outputDirectory>
<artifactItems>
<artifactItem>
Now, the issue appears to be related to a subset of the artifactItem - particular, artifactItems that do not have explicitly-defined destFileNames.
Long time coming back to this, but Gerold's comment lead me to the right resolution. The problem was the copy-dependencies happens after package. So the problem was that I was mvn clean compile, when I needed to be mvn clean package
I limped along taking way too long to sort that out. The fun of multi-module, interdependent projects

Is maven-download-plugin not portable, or am I crazy?

TL;DR: I stumbled upon a situation where my pom.xml works fine on Windows, but fails on Linux. Since I'm rather new to maven, I'm not sure whether it's a common situation, or if I messed up somewhere.
More details:
I use the maven-download-plugin like this:
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>maven-download-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>get-stuff</id>
<phase>generate-sources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://myUrl/my.tar.gz</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
On Windows it works like a charm (ie: it downloads and unpack).
On Linux, it fails with the following error:
[ERROR] Failed to execute goal com.googlecode.maven-download-plugin:maven-download-plugin:1.1.0:wget (get-moab)
on project my-project: Execution get-stuff of goal com.googlecode.maven-download-plugin:maven-download-plugin:1.1.0:wget failed:
An API incompatibility was encountered while executing com.googlecode.maven-download-plugin:maven-download-plugin:1.1.0:wget: java.lang.NoSuchMethodError: org.codehaus.plexus.util.cli.Commandline.createArg()Lorg/codehaus/plexus/util/cli/Arg;
I found a workaround (<unpack>false</unpack>, and then "manually" unpack with antrun), but my pom.xml looked better without those additional 15 lines...
To put it in a nutshell:
Is it actually a portability issue, or have I messed up somewhere?
If it's an portability issue: is it common with maven, or am I unlucky on this one?
More technical details:
I used the same plugin both on Linux and Windows (same version, same maven repository)
It failed on a Centos, and a VM with Ubuntu 12.04
My first troubleshooting step when a build works on one machine and not another is to clean out the local Maven repository on the failing machine, and let Maven re-download all of the artifacts. That's often enough to fix the problem.
If the build fails with the same error, then I clean out the local repository on the working machine and build. Usually then I see that I've missed a dependency in the POM that just happened to exist in my local repository already. Fixing the POM often makes the build work on both systems.
Did you check the Maven versions (mvn -version)? org.codehaus.plexus.util is a dependency of Maven Core, so if maven-download-plugin is running under a different version of Maven it was compiled for, this would explain the error.

Bootstrap, LESS and Maven plugin

I'm looking for some information on how to get LESS compiling Bootstrap using the Maven plugin. I need to compile bootstrap with my less because I use bootstrap less in my files. Right now I have the maven plugin compiling less files into css, but it breaks when I try to get it to compile bootstrap less. I think this might be a version issue, but just want to know if anyone's been able to figure this out or has a better approach.
pom.xml
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/webapp/less</sourceDirectory>
<outputDirectory>${project.build.directory}/${project.build.finalName}/css</outputDirectory>
<compress>true</compress>
<includes>
<include>bootstrap/bootstrap.less</include>
<include>test.less</include>
</includes>
<force>true</force>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
I running the above in a run configuration that calls "clean lesscss:compile"
error
Failed to execute goal org.codehaus.mojo:lesscss-maven-plugin:1.0-beta-3:compile (default-cli) on project FastTest: Error while compiling LESS source: bootstrap\alerts.less: Syntax Error on line 57: [object Object] (compile.js#1) -> [Help 1]
I'm not sure why it's going after the first item in the list for bootstrap so I renamed bootstrap.less to see if it ran and this is what I got:
Failed to execute goal org.codehaus.mojo:lesscss-maven-plugin:1.0-beta-3:compile (default-cli) on project FastTest: Error while compiling LESS source: bootstrap\abootstrap.less: Syntax Error on line 686: [object Object] (compile.js#1) -> [Help 1]
You are not compiling your code with correct plugin.
You are defining:
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
But from output it is obvious that a different plugin was triggered:
org.codehaus.mojo:lesscss-maven-plugin:1.0-beta-3
Seems a newer version of less is required for the maven plugin since bootstrap uses features that require less version 1.4.0
Your plugin-version issue notwithstanding, you can override the compiler being used by the Maven Plugin...
Download the latest lesscss JS file from lesscss.org, and put it in your project's scripts/js folder, then add a lessJs node into your plugin's configuration:
<configuration>
<lessJs>${project.basedir}/.../less.?.?.?.min.js</lessJs>
...
</configuration>
Now the plugin will use the JS file to compile, instead of it's own built-in, often outdated compiler.
I think the latest JS release is now 1.6.3.
Hope this helps!
Tze
If you are using the newest version of Bootstrap you will need Less 1.6.x to compile the Less files.
See http://blog.getbootstrap.com/2014/01/30/bootstrap-3-1-0-released/ that writes:
We've switched from Recess to grunt-contrib-less for our compiler, giving us access to Less 1.6.x (as opposed to 1.3.x with Recess).
The official Less Maven Plugin org.lesscss:lesscss-maven-plugin that you use does currently only support Less 1.3 and is not actively maintained at the moment. But I released a fork of it to Maven Central yesterday that supports Less 1.6.1 and contains other open pull requests from the plugin.
It is de.sandroboehme.lesscss:lesscss-maven-plugin:1.6.1.1.0 from https://github.com/sandroboehme/lesscss-java. Using it could solve your problem.
BTW: If somebody happens to be interested, contributers are wanted for the official Maven plugin. See https://github.com/marceloverdijk/lesscss-maven-plugin/issues/39
In the mean time I would use the Frontend Maven Plugin. See
https://github.com/eirslett/frontend-maven-plugin

Maven build number plugin, how to save the build number in a file?

I've a Java project using Spring Framework and Git and I wanted to display a build number. I found the Build Number Maven plugin. With Git the build number is a Git hash. I dislike that and I thought a date was much more expressive.
I found this excellent blog article explaining how to use build number plugin with a different profile for SVN and Git. Since I just use Git, instead of creating a new profile, I just copied the plugin part in my build tag.
When I run "mvn package" it tells me:
[INFO] --- buildnumber-maven-plugin:1.0:create (default) # sherd ---
[INFO] Storing buildNumber: 2011-08-04_21-48_stivlo at timestamp: 1312487296631
Which looks ok, but I wonder, where is it stored? "git status" doesn't detect any new file and it seems it's not in target/ too (target/ is in my .gitignore).
Maybe I've to change the configuration to store the build number in a file? How can I use the build number value?
Thanks to the hint of Michael-O, I read the chapter about how to filter resource files in Maven Getting Started Guide. I've created a file application.properties in src/main/resources/properties/application.properties with the following contents:
# application properties
application.name=${pom.name}
application.version=${pom.version}
application.build=${buildNumber}
I've added the following XML snippet within my build section:
<resources>
<resource>
<directory>src/main/resources/properties</directory>
<filtering>true</filtering>
</resource>
</resources>
Now when I call from command line "mvn package", this property file gets saved in target/classes/properties/application.properties, for instance with the following contents:
# application properties
application.name=Sherd Control Panel
application.version=1.0.1-SNAPSHOT
application.build=2011-08-05_05-55_stivlo
Everything works fine from command line, but, sigh, m2eclipse gives Build errors:
05/08/11 6.05.03 CEST: Build errors for obliquid-cp;
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.codehaus.mojo:buildnumber-maven-plugin:1.0:create (default) on project
sherd: Cannot get the branch information from the scm repository :
Exception while executing SCM command.
For some reason m2eclipse tries to connect to my repository, but it can't because it's a Git repository accessed with SSH and a private key. I wonder if I can tell m2eclipse to not connect to Git.
After more digging I found about revisionOnScmFailure option, set it to true and now also m2eclipse works. For reference, here is the full configuration of buildnumber maven plugin that I used (it goes in pom.xml in the build / plugins section).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>true</revisionOnScmFailure>
<format>{0,date,yyyy-MM-dd_HH-mm}_{1}</format>
<items>
<item>timestamp</item>
<item>${user.name}</item>
</items>
</configuration>
</plugin>
You shouldn't set revisionOnScmFailure option to true, it doesn't expect a boolean. Set it to revision string you want to use when SCM is unavailable, like na or like that. It doesn't matter for your case since you override the build number format but it would be more correct.
See buildnumber-maven-plugin docs.
Store it in a filtered properties file. See Using maven to output the version number to a text file
I could not reproduce the problem reported by the OP. In my case both command line and m2eclipse work fine and the file is generated correctly in the target/classes folder. The answer provided by #KasunBG is incorrect. The buildNumber.properties is generated only if you use the following:
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
buildNumber.properties is used to store a number which can be incremented. For this reason ( I think ) the plugin doesn't generate this file if you use timestamp/scmVersion etc.
The documentation page says that the properties files is stored at ${basedir}/buildNumber.properties, which is created when the buildnumber:create phase is ran.

Resources