Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
# JavaRepo
# [Codecov][0] Java Example

[![Build Status](https://travis-ci.org/codecov/example-java.svg?branch=master)](https://travis-ci.org/codecov/example-java)
[![codecov](https://codecov.io/gh/codecov/example-java/branch/master/graph/badge.svg)](https://codecov.io/gh/codecov/example-java)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java?ref=badge_shield)

## Guide

### Travis Setup

Add the following to your `.travis.yml`:
```yml
language: java
after_success:
- bash <(curl -s https://codecov.io/bash)
```

### Produce Coverage Reports
1. Add JaCoCo Plugin to your pom.xml file, [see here](https://github.com/codecov/example-java/blob/master/pom.xml#L43-L61)

## Caveats

#### Private Repo
You will need to add the following your `.travis.yml`:
```yml
env:
global:
- CODECOV_TOKEN=:uuid-repo-token
```

#### JaCoCo Reports

- Make sure you are using the latest version of JaCoCo. There are issues with previous versions of JaCoCo.
- JaCoCo reports can expire - Codecov will reject reports that are older than 12 hours. The logs contain details if a report expired.

## Support

### FAQ
- Q: How do I enable multi-module projects?<br/>A: In your `pom.xml` file please append a list of modules in your projects:
```xml
<project>
<modules>
<module>module_a/</module>
<module>module_b/</module>
</modules>
</project>
```
- Q: Seeing `Skipping JaCoCo execution due to missing execution data file`?<br/>A: Please see [http://stackoverflow.com/questions/18107375/...](http://stackoverflow.com/questions/18107375/getting-skipping-jacoco-execution-due-to-missing-execution-data-file-upon-exec).
- We should talk about using other CIs here.
- Q: Does Codecov accept `jacoco.exec` reports?<br/>A: **No**, these files are not supported. Please produce a `xml` file as detailed in the pom.xml file at [codecov/example-java][1].
- Q: Is there a Gradle example?<br/>A: **Yes**, enter [codecov/example-gradle][2]
- Q: Is there a Android example?<br/>A: **Yes**, enter [codecov/example-android][3]
- Q: Is there a Maven example?<br/>A: **Yes**, enter [codecov/example-maven][4]

1. More documentation at https://docs.codecov.io
2. Configure codecov through the `codecov.yml` https://docs.codecov.io/docs/codecov-yaml
3. View source and learn more about [Codecov Global Uploader](https://github.com/codecov/codecov-bash)

We are happy to help if you have any questions. Please contact email our Support at [support@codecov.io](mailto:support@codecov.io)

[0]: https://codecov.io/
[1]: https://github.com/codecov/example-java
[2]: https://github.com/codecov/example-gradle
[3]: https://github.com/codecov/example-android
[4]: https://github.com/codecov/example-java-maven
[5]: https://docs.codecov.io/docs/about-the-codecov-bash-uploader#section-upload-token


## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java?ref=badge_large)
70 changes: 70 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

Contributors:
Marc R. Hoffmann - initial API and implementation
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.examples.maven.java</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>JaCoCo Maven plug-in example for Java project</name>
<url>http://www.eclemma.org/jacoco</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>

</project>
13 changes: 13 additions & 0 deletions src/main/java/org/jacoco/examples/maven/java/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jacoco.examples.maven.java;

public class HelloWorld {

public String getMessage(boolean bigger) {
if (bigger) {
return "Hello Universe!";
} else {
return "Hello World!";
}
}

}
22 changes: 22 additions & 0 deletions src/test/java/org/jacoco/examples/maven/java/HelloWorldTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jacoco.examples.maven.java;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class HelloWorldTest {

private HelloWorld subject;

@Before
public void setup() {
subject = new HelloWorld();
}

@Test
public void testGetMessage() {
assertEquals("Hello World!", subject.getMessage(false));
}

}