4/20/2011

My mvn notes

To view dependency tree:

mvn dependency:tree
If you see the following errors when running dependency:tree, try upgrading the dependency plugin to version 2.8 or later.
[WARNING] Error injecting: org.apache.maven.shared.dependency.graph.internal.Maven3DependencyGraphBuilder
java.lang.NoClassDefFoundError: org/sonatype/aether/version/VersionConstraint

Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.version.VersionConstraint
 at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
 at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
 at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
 at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
 ... 62 more

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.6:tree (default-cli) on project: 
Execution default-cli of goal org.apache.maven.plugins:maven-dependency-plugin:2.6:tree failed: 
A required class was missing while executing org.apache.maven.plugins:maven-dependency-plugin:2.6:tree: 
org/sonatype/aether/version/VersionConstraint

To skip running tests:
mvn install -DskipTests
mvn install -DskipTests=true  //to override skipTests property in pom
To skip compiling and running tests:
mvn install -Dmaven.test.skip=true
To run maven in offline mode, to avoid downloading:
mvn -o install
mvn --offline install
To force check for updates of snapshots and releases from remote repositories:
mvn -U install
mvn --update-snapshots install
To list all maven profiles, and see which is the active profile:
mvn help:all-profiles
To override maven surefire plugin forkMode:
mvn test -DforkMode=never
mvn test -DforkMode=always
To debug a non-forked test, just need to attach the remote debugger to mvn process itself. mvnDebug is a convenience script located in the same directory as mvn executable:
mvnDebug test
mvnDebug test -DforkMode=never
To debug a forked test, you will need to set the debug option to the forked VM, not the mvn VM. The way to do it is to set -Dmaven.surefire.debug flag to mvn VM (the parent VM):
mvn test -Dmaven.surefire.debug
mvn test -Dmaven.surefire.debug -DforkMode=always
mvn test -Dmaven.surefire.debug -Dtest=com.my.test.MyTest#test1
To avoid OutOfMemoryError from running maven, especially maven 3, set environment variable MAVEN_OPTS:
# in $HOME/.tcshrc, or $HOME/.cshrc, if using csh or tcsh:
setenv MAVEN_OPTS "-Xmx1024m -XX:MaxPermSize=256m"

# in $HOME/.profile or $HOME/.bashrc, if using ksh or bash:
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m"

# in Windows Control Panel, or set it in DOS command line (This is Windows. DO NOT quote values):
set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=256m

To run individual unit test, use -Dtest system property. Copy reference on the test method in IDE to get the full test name (command-option-shift-c in Intellij on Mac):
mvn install -Dtest=test.UserTest#testNewUser
mvn test -Dtest=test.UserTest#testNewUser

To run individual integration test, use -Dit.test system property:
mvn install -Dit.test=test.UserTestIT#testLogin
mvn verify -Dit.test=test.UserTestIT#testLogin
mvn integration-test -Dit.test=test.UserTestIT#testLogin

To pass environment variables to tests executed with maven surefire plugin:
<build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <environmentVariables>
                            <JAVA_HOME>${env.JAVA_HOME}</JAVA_HOME>
                        </environmentVariables>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

To pass system properties to integration tests executed with failsafe plugin:
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.11</version>
                <configuration>
                    <systemPropertyVariables>
                        <project.build.directory>${project.build.directory}</project.build.directory>
                        <project.artifactId>${project.artifactId}</project.artifactId>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

To run mvn with an alternate user setting file, e.g., settings-jboss.xml:
mvn -s $HOME/.m2/settings-jboss.xml
The content of settings-jboss.xml:
<settings>
<repositories>
       <repository>
         <id>jboss-public-repository-group</id>
         <name>JBoss Public Maven Repository Group</name>
         <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
         <layout>default</layout>
         <releases>
           <enabled>true</enabled>
           <updatePolicy>never</updatePolicy>
         </releases>
         <snapshots>
           <enabled>true</enabled>
           <updatePolicy>never</updatePolicy>
         </snapshots>
       </repository>
     </repositories>
</settings>
When including mvn command in a Windows batch file, use call command.
call mvn clean install
cd integration-tests
call mvn clean install


To push tags to the remote repository:
git push --tags
To delete a tag and push this deletiion to the remote repository:
git tag (to list all tags)
git tag -d MS1
git push --delete origin MS1
To search for mvn surefire test failures on the screen: Ctrl-F <<<
<<< is probably the quickest way to find it. Searching for words like Failure gives too many results.

To increment or bump up artifact version:

mvn versions:set -DnewVersion=9.9.0-SNAPSHOT -DgenerateBackupPoms=false
This is useful when releasing a new version of the application. Note that the system propertygenerateBackupPoms=false tells maven not to generate pom.xml backup files.

4/01/2011

My vim notes

To open all files whose paths are stored in a file into multiple vim buffers:

cat list.txt | xargs vim
xargs vim < /tmp/a
To redirect the output from a command (ps) into vim for easy search and maybe saving it:
ps -ef | vim -
To combine vim and find to open all matched files:
vim `find . -name build.xml`
find . -name web.xml | xargs vim
find . -name web.xml -exec vim {} \; is different: it will find a match, vim it, and repeat, and only 1 buffer in any vim session.

Be careful with file names with spaces. These pipelined use of find and xargs will treat spaces as delimiter between args, and break one arg into two.

vim search & replace in a file(replace old with new in the whole file, CASE sensitive, asking for confirmation). When prompted for confirmation, press 'a' to confirm all ocurrences including and after the current one.
:%s/old/new/gcI
To replace all comma with a new line return: :s/,/\r/gp

To bookmark a location as bookmark a, type ma. To go to bookmark a, type 'a

To turn off syntax highlighting, run command ":sy off", or ":syn off", or ":syntax off", to turn on highlighting again ":sy on", or ":syn on", or ":syntax on". After typing ":sy", you can press TAB key for autocomplete, or press Ctrl-D to list all matching commands.

To turn off highlight after you are done with a search, run command ":nohl"

To turn on highight search, if it's not already on, run command ":set hls"

To save all changed files, run command ":wa"

To save all changed files and exit, run command ":xa"

":x" is the same as ":wq": save and exit

To close all files and exit, run command ":qa", but vim won't exit if there is unsaved changes.

To close all files and exit forcifully, run command ":q!".

To open a file and go the end of the file (to skip long copyright):
vim -c :$ pom.xml


To open a file (e.g., log file) in read-only mode and go to the end of file:
view -c :$ $JBOSS_HOME/standalone/log/server.log
vim -R -c :$ $JBOSS_HOME/standalone/log/server.log

The above commands are similar to tail -f, but easier to search and navigate inside vim.

To open a file with gvim or vim from Mac OS terminal, run
"open -a gvim build.xml"
If you configure Finder to always open *.xml files with gvim, directly run
"open build.xml"
You can still open them with the default TextEdit with
"open -a textedit build.xml"
To customize gvim window size (the default is too small), add the following lines to $HOME/.gvimrc on Mac/Linux/Solaris, or %HOMEPATH%\_gvimrc on Windows:
set lines=80 columns=120
To substitue the current character and stay in insertion mode, type s

To change to overwrite/replace mode (as opposed to insertion), shift-R (Uppercase R)

To undo the last undo: Ctrl-R

To search with case-insensitive option for this search only, /foo\c

To insert the current file name: Ctrl-R-Shift-% (useful when working on java and xml files to fill in class name or root element name.)