Blog

Maven Error: “Bare Repository has neither a working tree, nor an index”

I suddenly couldn’t build a Maven project at work because of the error below…. Did some googling but didn’t really find helpful info, other than that I was touching a “bare” repository. I thought about it for a second and realized that maybe my changing the artifact version in the pom had something to do with it (I did this as another branch had increased the version).

I quickly rolled it back to the previous version, committed and pushed, and, voila, Jenkins started building my project successfully again.

Adding it here in case someone gets bit with this [annoying] error.


18:17:46 [info] HEAD is [ de8cb9011de6b1fc101ac8133875aaf076b9bbe3 ]
18:17:46 org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
18:17:46 at org.eclipse.jgit.lib.Repository.getWorkTree(Repository.java:1246)
18:17:46 at org.eclipse.jgit.treewalk.FileTreeIterator.(FileTreeIterator.java:88)
18:17:46 at org.eclipse.jgit.api.StatusCommand.call(StatusCommand.java:126)
18:17:46 at pl.project13.jgit.DescribeCommand.findDirtyState(DescribeCommand.java:360)
18:17:46 at pl.project13.jgit.DescribeCommand.call(DescribeCommand.java:296)
18:17:46 at pl.project13.maven.git.JGitProvider.getGitDescribe(JGitProvider.java:225)
18:17:46 at pl.project13.maven.git.JGitProvider.getGitDescribe(JGitProvider.java:122)
18:17:46 at pl.project13.maven.git.GitDataProvider.maybePutGitDescribe(GitDataProvider.java:93)
18:17:46 at pl.project13.maven.git.GitDataProvider.loadGitData(GitDataProvider.java:63)
18:17:46 at pl.project13.maven.git.GitCommitIdMojo.loadGitDataWithJGit(GitCommitIdMojo.java:485)
18:17:46 at pl.project13.maven.git.GitCommitIdMojo.loadGitData(GitCommitIdMojo.java:457)
18:17:46 at pl.project13.maven.git.GitCommitIdMojo.execute(GitCommitIdMojo.java:315)
18:17:46 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
18:17:46 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
18:17:46 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
18:17:46 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
18:17:46 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
18:17:46 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
18:17:46 at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
18:17:46 at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
18:17:46 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
18:17:46 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
18:17:46 at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:117)
18:17:46 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
18:17:46 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
18:17:46 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
18:17:46 at java.lang.reflect.Method.invoke(Method.java:483)
18:17:46 at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)
18:17:46 at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
18:17:46 at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:178)
18:17:46 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
18:17:46 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
18:17:46 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
18:17:46 at java.lang.reflect.Method.invoke(Method.java:483)
18:17:46 at hudson.maven.Maven3Builder.call(Maven3Builder.java:136)
18:17:46 at hudson.maven.Maven3Builder.call(Maven3Builder.java:71)
18:17:46 at hudson.remoting.UserRequest.perform(UserRequest.java:121)
18:17:46 at hudson.remoting.UserRequest.perform(UserRequest.java:49)
18:17:46 at hudson.remoting.Request$2.run(Request.java:324)
18:17:46 at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
18:17:46 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
18:17:46 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
18:17:46 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
18:17:46 at java.lang.Thread.run(Thread.java:744)

My custom bash prompt

I wanted more information in my bash prompt, such as date/time and the directory I was in.  Here’s what it looks like:

bash_prompt

And this is what I added in my ~/.bash_profile:


PS1='${debian_chroot:+($debian_chroot)}\d \T > \[$(tput sgr0)\]\[\033[01;32m\]\u@\h\[\033[00m\] : \[\033[01;34m\]\w\[\033[00m\]\n\$ '

Run source ~/.bash_profile and enjoy. 🙂

BTW, there’s also a website that you can use to create your own: http://bashrcgenerator.com/.

Switching between multiple Java versions on OS X quickly

If you’re a Java developer like me, you will need to work on various Java versions. If so, adding the following in your ~./bash_profile makes switching between versions a snap. (As of this writing, I’m running on OS X El Capitan.)


alias java6='export JAVA_HOME=$(/usr/libexec/java_home -v 1.6);java -version'
alias java7='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7);java -version'
alias java8='export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);java -version'
alias java9='export JAVA_HOME=$(/usr/libexec/java_home -v 9);java -version'

NOTE: Java 9 above is the beta version, so it may be 1.9 once it’s been finalized.

Cannot find setclasspath.sh when starting up Tomcat 7

In attempting to start Tomcat 7 on my MacBook Pro on El Capitan, I was getting the following error:


amp-macbook:Cellar anton$ catalina start
Cannot find /usr/local/Cellar/tomcat7/7.0.63/libexec/bin/setclasspath.sh
This file is needed to run this program

I found the issue to be due to my CATALINA_HOME environment variable. To resolve this, just do the following from your terminal:


unset CATALINA_HOME

That’s it!