apache_maven

I was fighting today against the maven-release-plugin of maven, solving complicated  errors in a row. As I am convince I made all possible errors,   I think it is worse to compile my findings here to help others :-)

Maven Release Plugin

This plugin is used to release a project with Maven, saving a lot of repetitive, manual work. Releasing a project is made in two steps: prepare and perform.

My approach to speed up things is always to define a small project (in a sandbox SVN root) that is compiling and running in 10 seconds to make some test before trying to make it run on our bigger Innoveo Skye(tm) product (35 modules)

I always have 2 projects prepared:

  • One TestSimpleProject: one Maven project with no code
  • One TestComplexProject: one maven project and 2 Maven sub modules

For the reader that can not wait here is the running command line from TeamCity to be put in Build Runner Goals

release:clean release:prepare release:perform -Dusername=xxxxxxx -Dpassword=yyyyyy

 

Latest SVN client is  recommended

You need the latest SVN command line client on all TeamCity  agent, or  at least not any SVN command line client > 1.5.x which don’t work (but 1.5.0 would have). We were using 1.5.1 of course on all our server (Murphy’s laws)

Use at least a Subversion SVN client (1.6.6 as for today).

If you dont have any SVN command line installed in your TeamCity agents, you’'ll  end with this easy to understand error

[INFO] Unable to check for local modifications
[11:34:40]:
Provider message:
[11:34:40]:
The svn command failed.
[11:34:40]:
Command output:
[11:34:40]:
/bin/sh: svn: command not found
[11:34:40]:
[INFO] Trace
[11:34:40]:
org.apache.maven.BuildFailureException: Unable to check for local modifications
[11:34:40]:
Provider message:
[11:34:40]:
The svn command failed.
[11:34:40]:
Command output:
[11:34:40]:
/bin/sh: svn: command not found
[11:34:40]:
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
[11:34:40]:
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
[11:34:40]: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)

The  maven release plugin require SVN client to be installed.

Update maven-release-plugin to the latest

You need to update maven-release-plugin away from 2.0.beta9 to 2.0 to solve the issue with multi module release. Luckily for me the 2.0 is available since 10 February 2010 Older version were working for simple Maven project (a project with no Maven module)  but not with Multi Modules Projects!

With 2.0-beta9 I was getting this error in Multi Modules Projects!

[18:41:46]: [ERROR] BUILD FAILURE
[18:41:46]: [INFO] ------------------------------------------------------------------------
[18:41:46]: [INFO] Unable to tag SCM
[18:41:46]: Provider message:
[18:41:46]: The svn tag command failed.
[18:41:46]: Command output:
[18:41:46]: svn: Commit failed (details follow):
[18:41:46]: svn: File '/svn/xxxxx/skye/tags/skye-2.1.0.M8/skye-admin/pom.xml' already exists
[18:41:46]: [INFO] Trace
[18:41:46]: org.apache.maven.BuildFailureException: Unable to tag SCM
[18:41:46]: Provider message:
[18:41:46]:
The svn tag command failed.
[18:41:46]: Command output:
[18:41:46]: svn: Commit failed (details follow):
[18:41:46]: svn: File '/svn/xxxxx/skye/tags/skye-2.1.0.M8/skye-admin/pom.xml' already exists

Invalid certificate handling

Sometimes an issue if you craft some certificate yourself, You need to import certificate in each TeamCity build agent by running

# svn co https://svn.xxxxxx.com/svn/yyyyyy/skye

at least once and accepting permanently the certificate (break the command afterward) Do this with the same UNIX user under which the agent run or you’ll always get this error:

[11:52:11]: [ERROR] BUILD FAILURE
[11:52:11]:
[INFO] ------------------------------------------------------------------------
[11:52:11]:
[INFO] Unable to checkout from SCM
[11:52:11]:
Provider message:
[11:52:11]:
The svn command failed.
[11:52:11]:
Command output:
[11:52:11]:
svn: OPTIONS of 'https://xxxxx.: Server certificate verification failed: certificate issued
                  for a different hostname, issuer is not trusted (xxxxxxxxx)
[11:52:11]:
[INFO] Trace
[11:52:11]:
org.apache.maven.BuildFailureException: Unable to checkout from SCM
[11:52:11]:
Provider message:
[11:52:11]:
The svn command failed.
[11:52:11]: Command output:

Maven 2.2.1 wrongly calculate SCM commit URL

You can not use in <scm> tag this kind of URL’s https://user:This email address is being protected from spambots. You need JavaScript enabled to view it.  like in the example below:

<scm>
<connection>scm:svn:https://username:This email address is being protected from spambots. You need JavaScript enabled to view it./svn/yyyyy/skye/trunk/skye</connection>
<developerConnection>scm:svn:https://username:This email address is being protected from spambots. You need JavaScript enabled to view it./svn/yyyyy/skye/trunk/skye</developerConnection>
<url>scm:svn:https://username:This email address is being protected from spambots. You need JavaScript enabled to view it./svn/yyyyy/skye/trunk/skye</url>
</scm>

Even if the documentation state otherwise, as the maven-release-plugin go “crazy” by concatenating wrongly the tagging URL.

[17:32:47]: [INFO] Working directory: /home/agent/buildagent/work/3d299c4b925af39b/TestRelease
[17:32:47]: [INFO] ------------------------------------------------------------------------
[17:32:47]:
[ERROR] BUILD FAILURE
[17:32:47]:
[INFO] ------------------------------------------------------------------------
[17:32:47]:
[INFO] Unable to tag SCM
[17:32:47]:
Provider message:
[17:32:47]:
The svn tag command failed.
[17:32:47]:
Command output:
[17:32:47]:
svn: Source and dest appear not to be in the same repository
                     (src: 'https://svn.xxxxxx.com/svn/xxxxxxx/Sandbox/trunk';
                     dst: 'https://xxxxxxx:This email address is being protected from spambots. You need JavaScript enabled to view it./svn/xxxxxx/Sandbox/tags/TestRelease-0.0.11')
[17:32:47]: [INFO] ------------------------------------------------------------------------

I found a workaround by adding environment variables in the TeamCity build in the list of Maven Goals:                 

–Dusername=xxxx –Dpassword=yyyy

Beware of invalid SCM URL

SCM (Software Configuration Management, also called Source Code/Control Management or, succinctly, version control) is an integral part of any healthy project. If your Maven project uses an SCM system (it does, doesn't it?) then here is where you would place that information into the POM.

A lot of example are floating around in internet about <scm> values that look like this:

<scm>
<connection>scm:svn:https://svn.xxxxx.com/svn/yyyyy/skye/trunk</connection>
<developerConnection>scm:svn:https://svn.xxxxx.com/svn/yyyyy/skye/trunk/</developerConnection>
<url>scm:svn:https://svn.xxxx.com/svn/yyyyy/skye/trunk/skye</url>
</scm>

With the above, you’ll end up tagging your whole trunk under a new tags in https://svn.xxxxx.com/svn/yyyyy/skye/tags/skye-2.1.0

No one is saying that you' should better have this, end up your scm connection with the project you would like to tag

<scm>
<connection>scm:svn:https://svn.xxxxx.com/svn/yyyyy/skye/trunk/skye</connection>
<developerConnection>scm:svn:https://svn.xxxx.com/svn/yyyyy/skye/trunk/skye</developerConnection>
<url>scm:svn:https://svn.xxxx.com/svn/yyyyy/skye/trunk/skye</url>
</scm>

Failure to deploy newly artifact

This one is also irritating, because running a build in TeamCity with the goal : deploy run perfectly, the same build in prepare:release perform:release failed miserably at the end with

INFO] [ERROR] BUILD ERROR
[19:26:08]: [INFO] [INFO] ------------------------------------------------------------------------
[19:26:08]: [INFO] [INFO] Error deploying artifact: Failed to transfer file: http://artifactory.xxxxxx.com:/libs-releases-local/…
                                       . Return code is: 401[19:26:08]:
[ERROR] BUILD ERROR
[19:26:08]:
[INFO] ------------------------------------------------------------------------
[19:26:08]:
[INFO] Maven execution failed, exit code: '1'
[19:26:08]: [INFO] ------------------------------------------------------------------------
[19:26:08]:
[INFO] Trace
[19:26:08]:
org.apache.maven.lifecycle.LifecycleExecutionException: Maven execution failed, exit code: '1'
[19:26:08]:
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
[19:26:08]: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)

I was not able to find a workaround to this one, the build is running without the maven-release-plugin and deploy correctly to artifactory! But I managed to get around it by using in place of the stable Maven 2.2.1 the latest version 3.0.alpha7!!!!

I hope this post will help some of you.

comments powered by Disqus

You might like also

Fetching artifact programmatically through REST/API in Nexus 3.x
There is so many case where it is desirable to pull down artifact from Sonatype Nexus using REST API, unfortunately Nexus 3.x Rest API are still under development... Some use cases in Nexus 2.x: You have a script that uses REST call to pull down the LATEST maven artifacts every night from Nexus and deploys them. You make extensive use of the REST API in all your puppet modules You use the Atlassian Puppet module for Nexus for creating repository, …
723 Days ago
git-branch-renamer-maven-plugin
When working with many feature/release/bugix/hotfix branches, it is a bad idea to start changing the pom version as this will create merge conflicts using pull request. this plugin allow you to keep in ALL branches the same pom version for all your projects, for example MASTER-SNAPSHOT the version will be derived from branch name automagically :-) You may want to read more first these 2 short articles Update Maven pom version on GIT checkout in TeamCity maven-release-plugin with GIT git-branch-renamer-maven-plugin …
735 Days ago
Review: Getting Started with Apache Maven by Russell Gold
Some time ago I was asked if I would like to write a review about one of the new video courses from Packt Publishing. It was "Getting Started with Apache Maven" http://bit.ly/1fycmpP by Russell Gold and since I have been using Maven for some years now (since 2007) and did publish some articles myself, I thought it would be nice to help them promote Apache Maven. The course is organized in eight chapters, forty videos with a length between two …
1922 Days ago
Update Maven pom version on GIT checkout in TeamCity
Here is a solution to the following problems Deriving Maven artifact version from GIT branch, Update pom version on GIT checkout automatically, Add the ability to use Pull request with Apache Maven. You have a workflow requirement that require you to have the artifact version of a module externally defined from the current branch in GIT. For example You want to start working on a new feature branch “feature-memory-improvement”, so you branch from master a new branch named feature/feature-memory-improvement Having …
1927 Days ago
Easily Compress Web Application Resources with EhCache
Resources such as JavaScript and CSS files can be compressed before being sent to the browser, improving network efficiencies and application load time in certain case. If you are not using Apache with mod_deflate or nginx in front of your web application, you may need to implement resources compression yourself…. Wait! don’t start writing your own filter to compress files like CSS, html, txt, javascript it is way more difficult than you think to properly handle http response headers and …
2409 Days ago
Tomcat 7 and Apache Maven
Here is 3 different way to control the lifetime a local Tomcat 7 container using Apache Maven. A typical scenario would be to start a servlet container prior to running integration tests (Selenium, SAHI or using any other framework you can think of ) With the following examples, you will be able to start an instance of Tomcat 7 running your web application in the pre-integration-test phase and stop the instance in the post-integration-test phase. You can also decide to …
2409 Days ago
Apache Maven copy local file to a remote server server using SSH
I will show you in an Apache Maven configuration file how to copy files to server each time the package phase is executed. Solution with Ant SCP task This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a maven mvn package, you can …
2597 Days ago
Apache M2Eclipse: Get rid of Duplicate resources when opening resources and types
In this small post, I’ll show you how to remove duplicated resources in the Open Resource view of Eclipse Eclipse – M2Eclipse – Subversive …
2603 Days ago
Apache Maven 3 Cookbook
&160; First a big thanks to Packt Publishing for having sent me this book to review! I did enjoy going through this book, while I did not learn a lot of new stuff (I am using Apache Maven daily since 2006!), I found it to be concise and would recommend it anytime to any of my colleagues. But let’s go through my review of this cookbook of over 50 recipes towards optimal Java Software Engineering with Maven 3: Apache Maven
2745 Days ago
Apache Maven 3 Cookbook Review
Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the next coming days Grasp the fundamentals and extend Apache Maven 3 to meet your needs Implement engineering practices in your application development process with Apache Maven Collaboration techniques for Agile teams with Apache Maven Use Apache Maven with Java, Enterprise Frameworks, and various other cutting-edge technologies Develop for Google Web Toolkit, Google App Engine, and Android Platforms using Apache Maven You …
2791 Days ago