My Jacoco Maven Plugin POM config

Adding it here so I can refer to it in the future.


<jacoco.version>0.8.2</jacoco.version>
        <min.branch.coverage>0.95</min.branch.coverage>
        <min.line.coverage>0.95</min.line.coverage>


<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>default-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule implementation="org.jacoco.maven.RuleConfiguration">
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit implementation="org.jacoco.report.check.Limit">
                                            <counter>BRANCH</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>${min.branch.coverage}</minimum>
                                        </limit>
                                        <limit implementation="org.jacoco.report.check.Limit">
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>${min.line.coverage}</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Maven error with Java 6 on OS X: “Unsupported major.minor version 51.0”

If you encounter the error below with Java 6 on OS X, make sure you’re using Maven 3.2.5 or older.

$ mvn
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
  at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
  at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
  at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
  at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
  at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Maven error in OS X: “Maven already installed, it’s just not linked”

If you use Homebrew on OS X and you come across the error below, just:

  1. $ rm -rf /usr/local/Cellar/maven
  2. $ brew install maven
  3. $ mvn -version
  4. That’s it!

$ brew install maven
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (caskroom/cask, caskroom/versions).

Warning: maven-3.5.0 already installed, it's just not linked.

Maven build error: “Caused by: java.io.IOException: Incompatible version 1007”

I was encountering this error in Jenkins when it tried to build a project I was working on:


Caused by: java.io.IOException: Incompatible version 1007.
at org.jacoco.core.data.ExecutionDataReader.readHeader(ExecutionDataReader.java:127)
at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:107)
at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:87)
at org.sonar.plugins.jacoco.AbstractAnalyzer.readExecutionData(AbstractAnalyzer.java:134)
at org.sonar.plugins.jacoco.AbstractAnalyzer.analyse(AbstractAnalyzer.java:107)

The problem was due to a breakage/bug in the jacoco-maven-plugin. To fix, simply add a version in your pom.xml, like so:


<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.4.201502262128</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>

That’s it!

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)