Building the client library for Java from source

We recommend using the client library through Maven. We also provide binary distributions on our releases page and through the Maven central repository (see our quick start guide for details). However, you can build the library yourself using one of the build processes described below.

The client library can be built with Apache Maven or Gradle. Both will manage and resolve dependencies, compile, package, and install the client library. Dependencies are downloaded from the Maven Central repository.

Install Java development kit

JDK 1.8 or later is required to build the library. We'll assume that Java is installed on your machine for the purposes of this guide.

Building with Apache Maven

We advise using at least Maven version 3.5.0 (although versions later than 3.0.0 should also be functional).

Linux

Maven is commonly available through operating system package managers. For example:

# Debian-based systems (Debian/Ubuntu/Mint etc.)
sudo apt-get install maven

# Redhat-based systems (Fedora/RHEL/CentOS etc.)
sudo yum install maven

Alternatively, download and install from the Apache Maven website.

MacOS & Windows

Download and install from the Apache Maven website.

Build the library

  1. Clone this project in the directory of your choice.

    git clone https://github.com/googleads/google-ads-java.git
    
  2. Navigate to the google-ads-java directory.

    cd google-ads-java
    
  3. Run the following command to install the snapshot version of the library and examples project.

    mvn clean install
    

Use the client library to call the API from another project

You can use the client library artifacts directly as dependencies (in other words, outside of Maven/Gradle such as in the IDE build system). However, this is strongly discouraged.

In addition to the JAR from google-ads/target, you will likely also need the JARs for all dependencies.

Run the following command to copy the dependencies to a target directory:

mvn dependency:copy-dependencies -f google-ads/pom.xml

Optionally, specify -DoutputDirectory=/copy/here to copy to a specified directory.

Building with Gradle

We recommend using the included Gradle wrapper. See gradle/wrapper/gradle-wrapper.properties for the current version. You do not need a separate Gradle installation.

Build the library

  1. Clone this project in the directory of your choice.

    git clone https://github.com/googleads/google-ads-java.git
    
  2. Navigate to the google-ads-java directory.

    cd google-ads-java
    
  3. Run the following command to build the snapshot version of the library and examples project.

    ./gradlew build
    
  4. Export the client library to a local Maven repository.

    ./gradlew publishToMavenLocal
    

Use the client library in a local Maven repository

After a successful build and export, the artifacts for the client library are available to Maven/Gradle from the local repository (typically ~/.m2/repository/com/google/api-ads/google-ads/). Add a dependency on the SNAPSHOT version that was just built to any subsequent project build files.