GitLab API for Java (gitlab4j-api) provides a full featured and easy to consume Java API for working with GitLab repositories via the GitLab REST API. Additionally, full support for working with GitLab webhooks and system hooks is also provided.
GitLab4J™ API (gitlab4j-api) provides a full featured and easy to consume Java library for working with GitLab repositories via the GitLab REST API. Additionally, full support for working with GitLab webhooks and system hooks is also provided.
---
---
To utilize the GitLab API for Java in your project, simply add the following dependency to your project's build file:
To utilize GitLab4J™ API in your Java project, simply add the following dependency to your project's build file:<br/>
**NOTE:** Pulling dependencies may fail when using Gradle prior to 4.5. See [Gradle issue 3065](https://github.com/gradle/gradle/issues/3065#issuecomment-364092456)
**NOTE:** Pulling dependencies may fail when using Gradle prior to 4.5. See [Gradle issue 3065](https://github.com/gradle/gradle/issues/3065#issuecomment-364092456)
**Maven: pom.xml**
**Maven: pom.xml**
```xml
```xml
<dependency>
<dependency>
<groupId>org.gitlab4j</groupId>
<groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId>
<artifactId>gitlab4j-api</artifactId>
<version>4.10.9</version>
<version>4.10.9</version>
</dependency>
</dependency>
```
```
**Ivy and SBT**<br/>
**Ivy and SBT**<br/>
There have been reports of problems resolving some dependencies when using Ivy or SBT, for help resolving those issues see:<br/>
There have been reports of problems resolving some dependencies when using Ivy or SBT, for help resolving those issues see:<br/>
<ahref="https://github.com/eclipse-ee4j/jaxrs-api/issues/571">JAX-RS API Issue #571</a><br/>
<ahref="https://github.com/eclipse-ee4j/jaxrs-api/issues/571">JAX-RS API Issue #571</a><br/>
<ahref="https://github.com/eclipse-ee4j/jaxrs-api/issues/572">JAX-RS API Issue #572</a>
<ahref="https://github.com/eclipse-ee4j/jaxrs-api/issues/572">JAX-RS API Issue #572</a>
---
---
## Javadocs
## Javadocs
Javadocs are available here: <ahref="http://www.messners.com/gitlab4j-api/javadocs/index.html?overview-summary.html"target="_top">Javadocs</a>
Javadocs are available here: <ahref="http://www.messners.com/gitlab4j-api/javadocs/index.html?overview-summary.html"target="_top">Javadocs</a>
---
---
## Java 8 Requirement
## Java 8 Requirement
As of GitLab4J-API 4.8.0, Java 8+ is now required to use GitLab4J-API.
As of GitLab4J-API 4.8.0, Java 8+ is now required to use GitLab4J-API.
---
---
## Using GitLab4J
## Using GitLab4J
GitLab4J-API is quite simple to use, all you need is the URL to your GitLab server and the Private Token from your GitLab Account Settings page. Once you have that info it is as simple as:
GitLab4J-API is quite simple to use, all you need is the URL to your GitLab server and the Private Token from your GitLab Account Settings page. Once you have that info it is as simple as:
```java
```java
// Create a GitLabApi instance to communicate with your GitLab server
// Create a GitLabApi instance to communicate with your GitLab server
As of GitLab4J-API 4.6.6, all API requests support performing the API call as if you were another user, provided you are authenticated as an administrator:
As of GitLab4J-API 4.6.6, all API requests support performing the API call as if you were another user, provided you are authenticated as an administrator:
```java
```java
// Create a GitLabApi instance to communicate with your GitLab server (must be an administrator)
// Create a GitLabApi instance to communicate with your GitLab server (must be an administrator)
As of GitLab 11.0 support for the GitLab API v3 has been removed (see https://about.gitlab.com/2018/06/01/api-v3-removal-impending/). Support for GitLab API v3 will be removed from this library in January 2019. If you are utilizing the v3 support, please update your code before January 2019.
As of GitLab 11.0 support for the GitLab API v3 has been removed (see https://about.gitlab.com/2018/06/01/api-v3-removal-impending/). Support for GitLab API v3 will be removed from this library in January 2019. If you are utilizing the v3 support, please update your code before January 2019.
---
---
## Logging of API Requests and Responses
## Logging of API Requests and Responses
As of GitLab4J-API 4.8.39 support has been added to log the requests to and the responses from the
As of GitLab4J-API 4.8.39 support has been added to log the requests to and the responses from the
GitLab API. Enable logging using one of the following methods on the GitLabApi instance:
GitLab API. Enable logging using one of the following methods on the GitLabApi instance:
As of GitLab4J-API 4.9.2, all GitLabJ-API methods that return a List result have a similarlly named method that returns a Java 8 Stream. The Stream returning methods use the following naming convention: ```getXxxxxStream()```.
As of GitLab4J-API 4.9.2, all GitLabJ-API methods that return a List result have a similarlly named method that returns a Java 8 Stream. The Stream returning methods use the following naming convention: ```getXxxxxStream()```.
**IMPORTANT**
**IMPORTANT**
The built-in methods that return a Stream do so using ___eager evaluation___, meaning all items are pre-fetched from the GitLab server and a Stream is returned which will stream those items. **Eager evaluation does NOT support paralell reading of data from ther server, it does however allow for paralell processing of the Stream post data fetch.**
The built-in methods that return a Stream do so using ___eager evaluation___, meaning all items are pre-fetched from the GitLab server and a Stream is returned which will stream those items. **Eager evaluation does NOT support paralell reading of data from ther server, it does however allow for paralell processing of the Stream post data fetch.**
To stream using ___lazy evaluation___, use the GitLab4J-API methods that return a ```Pager``` instance, and then call the ```lazyStream()``` method on the ```Pager``` instance to create a lazy evaluation Stream. The Stream utilizes the ```Pager``` instance to page through the available items. **A lazy Stream does NOT support parallel operations or skipping.**
To stream using ___lazy evaluation___, use the GitLab4J-API methods that return a ```Pager``` instance, and then call the ```lazyStream()``` method on the ```Pager``` instance to create a lazy evaluation Stream. The Stream utilizes the ```Pager``` instance to page through the available items. **A lazy Stream does NOT support parallel operations or skipping.**
**Eager evaluation example usage:**
**Eager evaluation example usage:**
```java
```java
// Stream the visible projects printing out the project name.
// Stream the visible projects printing out the project name.
GitLab4J-API supports Java 8 Optional<T> for API calls that result in the return of a single item. Here is an example on how to use the Java 8 Optional<T> API calls:
GitLab4J-API supports Java 8 Optional<T> for API calls that result in the return of a single item. Here is an example on how to use the Java 8 Optional<T> API calls:
GitLab issues allow for time tracking. The following time units are currently available:
GitLab issues allow for time tracking. The following time units are currently available:
* months (mo)
* months (mo)
* weeks (w)
* weeks (w)
* days (d)
* days (d)
* hours (h)
* hours (h)
* minutes (m)
* minutes (m)
Conversion rates are 1mo = 4w, 1w = 5d and 1d = 8h.
Conversion rates are 1mo = 4w, 1w = 5d and 1d = 8h.
---
---
## Making API Calls
## Making API Calls
The API has been broken up into sub API classes to make it easier to consume and to separate concerns. The GitLab4J sub API classes typically have a one-to-one relationship with the API documentation at [GitLab API](https://docs.gitlab.com/ce/api/). Following is a sample of the GitLab4J sub API class mapping to the GitLab API documentation:
The API has been broken up into sub API classes to make it easier to consume and to separate concerns. The GitLab4J sub API classes typically have a one-to-one relationship with the API documentation at [GitLab API](https://docs.gitlab.com/ce/api/). Following is a sample of the GitLab4J sub API class mapping to the GitLab API documentation:
The following is a list of the available sub APIs along with a sample use of each API. See the <a href="http://www.messners.com/gitlab4j-api/javadocs/index.html?org/gitlab4j/api/package-summary.html" target="_top">Javadocs</a> for a complete list of available methods for each sub API.
The following is a list of the available sub APIs along with a sample use of each API. See the <a href="http://www.messners.com/gitlab4j-api/javadocs/index.html?org/gitlab4j/api/package-summary.html" target="_top">Javadocs</a> for a complete list of available methods for each sub API.