JPragma Blog

Pragmatic Developers, Elegant Software

Project release and version management using gradle and git

leave a comment »

Two very useful Gradle plugins:

1. axion-release-plugin

This plugin derives project version from tags in git repository. I use following rules in my projects:

  • Start with default version 0.1.0-SNAPSHOT
  • Every release of master branch increments second digit
  • Production emergency fixes are done on a branch, which is created from the version tag. Such branch name must start with “hotfix-” prefix. Releasing this branch will increment 3rd digit.
  • Feature branches must have “topic-” prefix. They are never released, however their version includes feature name.

To check current project version run “gradle currentVersion”
To release the project run “gradle release”

2. gradle-nexus-plugin

This plugin adds ability to upload project artifacts to nexus repository. Simply run “gradle upload”.


buildscript {
    repositories {
        maven {url = ''}

plugins {
    id 'java'
    id '' version '1.3.4'
    id '' version '2.3.1'

scmVersion {
    versionIncrementer 'incrementMinor'
    branchVersionIncrementer = [
            'hotfix-.*' : { c -> c.currentVersion.incrementPatchVersion() }
    branchVersionCreator = [
            'topic-.*' : 'versionWithBranch'

group 'com.jpragma.myproject'
version = scmVersion.version

repositories {
    jcenter {url = ''}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.21'
    testCompile 'junit:junit:4.12'

nexus {
    sign = false
    repositoryUrl = 'http://localhost:8081/nexus/content/repositories/internal/'
    snapshotRepositoryUrl = 'http://localhost:8081/nexus/content/repositories/internal-snapshots/'

Written by isaaclevin

July 12, 2016 at 2:03 pm

Posted in Uncategorized

Useful aliases and ENVs in cygwin .profile

leave a comment »

alias cp=’cp -i’
alias mv=’mv -i’
alias df=’df -h’
alias du=’du -h’
alias grep=’grep –color’
alias itest=’mvn clean test verify -U’
alias ls=’ls -h –color’
alias mci=’mvn clean install -U’
alias mi=’mvn install’
alias mjr=’mvn jetty:run -o’
alias mjrwithprofile=’mvn clean jetty:run -DAPP_ENV=dev’
alias ps=’ps -W -a -f ux’
alias rm=’rm -i’

function xtitle {
echo -ne “\033]0;$1\007″

export MAVEN_OPTS_BASE=”-server -Xms128m -Xmx2048m -XX:MaxPermSize=256m”
export MAVEN_OPTS_DEBUG=”$MAVEN_OPTS_BASE -Xdebug=true -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=5555,server=y,suspend=n″
alias mvnAllOff=’export MAVEN_OPTS=$MAVEN_OPTS_BASE’
alias mvnDebugOn=’export MAVEN_OPTS=$MAVEN_OPTS_DEBUG’


Written by isaaclevin

May 11, 2016 at 8:45 am

Posted in Uncategorized

Useful options running “mvn test”

with one comment

There are some very useful command line options you can specify when executing maven tests:

-Dtest=[testname], this allows selective execution of unit tests, instead of running them all. [testname] might be full class name, class name without package, or even wildcard.

-Dsurefire.useFile=false, this will force surefire plugin to write failing test info to stdout instead of file in target/surefire-reports/. Can be a huge time saver.

Written by isaaclevin

January 28, 2011 at 12:58 pm

Posted in Java

Control Log4j message timezone

leave a comment »

If your server is running in one timezone, but you want to have log messages be printed using different timezone, here is a simple solution:

  1. Add log4j extras to project classpath (maven GAV is log4j:apache-log4j-extras:1.0)
  2. In log4j.xml use EnhancedPatternLayout, specifying required timezone for logging purposes (see example below for EST TZ)
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <param name="Threshold" value="TRACE" />
    <layout class="org.apache.log4j.EnhancedPatternLayout">
        <param name="ConversionPattern" value="%d{ISO8601}{EST} %-5p [%t][%c:%M(%L)] %m%n" />

In this example, log messages will be printed using EST regardless of your server timezone.

Written by isaaclevin

December 27, 2010 at 3:23 pm

Posted in Java

Setting timeout on Axis WebService calls

with 2 comments

In several projects we participated, there was a need to call external Web Services using Java classes generated by wsdl2java Axis tool (or wsdl2java goal of axistools-maven-plugin).

Sometimes these external systems that exposed Web Services experienced high load, slow database and other factors, which caused our calls to them to take outrageously long time before the response have been received.
So, we had to introduce timeouts and handle such calls as errors.

Looking into Axis documentation we found that there is a wsdl2java “timeout” parameter available in both command line tool and via maven plugin. However setting this parameter had no effect, our calls were still hanging indefinitely. It’s not even clear from the documentation if this timeout is applied to webservice call or to execution of wsdl2java itself.

Anyways to have a timeout on webservice call the one must be set on instance of org.apache.axis.client.Call prior to calling invoke(). But creation of Call instance and setting of all its properties is done from Axis generated code and all your changes there will be overwritten on next wsdl2java run.

The solution is to set timeout property on the class that extends org.apache.axis.client.Stub, it’s Axis generated class and would be called something like MyWebServicePort_PortType. If timeout on Call is not set it uses the value from Stub.
This solution is also much more flexible, because now you can set different timeouts on various calls depending on your business logic.

Written by isaaclevin

December 17, 2010 at 11:02 am

Posted in Java

Tagged with , , ,

Finding unused code in Java projects

with one comment

In many projects, especially big ones, developed over several years, there is a lot unused code. Cleaning up projects and deleting such unused code is important.

Unfortunately all above methods will mark code invoked by reflection (e.g. using IoC container such as Spring) as unused. At the same time garbage code that was left behind together with its unit test won’t be detected.

I see only one way to detect such obsolete code – run the system for a while through all typical scenarios and collect statistics on loaded classes, invoked methods, etc. Of course report generated using this technique can be only considered as a hint and manual verification is required.
Proper solution should probably be done using AOP, instrumenting code either during compile or load time. There is however quick and dirty way that archives similar results.

  1. Run your app with -verbose:class option (send standard output to file in addition to console using | tee <filename>)
    $ export MAVEN_OPTS="$MAVEN_OPTS -verbose:class"
    $ mvn clean jetty:run | tee jetty.log
  2. Execute all typical scenarios of your application
  3. From generated log file create sorted list of your project classes used in executed scenarios:
    $ grep "\[Loaded.*com.jpragma" jetty.log | awk '{print $2}' | sort | uniq -u > loaded_classes.txt
  4. Create sorted list of your compiled project classes:
    $ find target/classes/ -name *.class | sed 's/target\/classes\/\///g' \
    | sed 's/.class//g' | tr -s '/' '.' \
    | sort > declared_classes.txt
  5. Compare two txt files finding all classes that declared but not used:
    $ diff loaded_classes.txt declared_classes.txt | grep ">"

Written by isaaclevin

February 14, 2010 at 7:24 pm

Posted in Java

Insert semicolons and braces in correct position

leave a comment »

One thing that always disturbed me when editing Java source files is that you need to move your hands out of keyboard’s home row, press <End> and then type semicolon or open brace. Not anymore! I recently discovered pretty cool feature in Eclipse that automatically inserts semicolons and braces in correct positions.

Enable this option via Preferences -> Java -> Editor -> Typing dialog.

Written by isaaclevin

February 14, 2010 at 7:23 pm

Posted in Uncategorized